保存后的mongodb 示例
时间: 2023-07-08 21:55:29 浏览: 71
以下是保存后的 MongoDB 示例:
假设我们有一个名为“users”的集合,其中包含以下文档:
```
{
"_id": ObjectId("6107f9c07a35b81d6d6f6fb4"),
"name": "Alice",
"age": 25,
"email": "alice@example.com"
},
{
"_id": ObjectId("6107fa2b7a35b81d6d6f6fb5"),
"name": "Bob",
"age": 30,
"email": "bob@example.com"
},
{
"_id": ObjectId("6107fa3e7a35b81d6d6f6fb6"),
"name": "Charlie",
"age": 35,
"email": "charlie@example.com"
}
```
我们可以使用以下命令将文档插入到“users”集合中:
```
db.users.insert({
"name": "David",
"age": 40,
"email": "david@example.com"
})
```
插入后,我们的“users”集合将包含以下文档:
```
{
"_id": ObjectId("6107f9c07a35b81d6d6f6fb4"),
"name": "Alice",
"age": 25,
"email": "alice@example.com"
},
{
"_id": ObjectId("6107fa2b7a35b81d6d6f6fb5"),
"name": "Bob",
"age": 30,
"email": "bob@example.com"
},
{
"_id": ObjectId("6107fa3e7a35b81d6d6f6fb6"),
"name": "Charlie",
"age": 35,
"email": "charlie@example.com"
},
{
"_id": ObjectId("6111d5b2b6c4d927b1a6b34d"),
"name": "David",
"age": 40,
"email": "david@example.com"
}
```
注意,插入文档时,MongoDB会自动分配一个唯一的_id值作为文档的主键。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)