mongodb操作
mongotemplate mongodb常见操作

mongotemplate mongodb常见操作MongoTemplate是Spring提供的用于操作MongoDB的一个工具类,它封装了一系列常见的MongoDB操作。
1. 插入文档:```MongoTemplate mongoTemplate;mongoTemplate.insert(objectToSave, collectionName);```2. 更新文档:```Query query = new Query(Criteria.where("field").is(value)); Update update = new Update().set("fieldToUpdate", newValue); mongoTemplate.updateMulti(query, update, collectionName);```3. 删除文档:```Query query = new Query(Criteria.where("field").is(value)); mongoTemplate.remove(query, collectionName);```4. 查询文档:```Query query = new Query(Criteria.where("field").is(value));List<T> results = mongoTemplate.find(query, T.class, collectionName);```5. 条件查询:```Query query = new Query();query.addCriteria(Criteria.where("field").is(value));List<T> results = mongoTemplate.find(query, T.class, collectionName);```6. 分页查询:```Query query = new Query().skip(page * size).limit(size); List<T> results = mongoTemplate.find(query, T.class, collectionName);```7. 聚合查询:```Aggregation aggregation = Aggregation.newAggregation( Aggregation.match(Criteria.where("field").is(value)), Aggregation.group("groupField").count().as("count") );AggregationResults<ResultType> result = mongoTemplate.aggregate(aggregation, collectionName, ResultType.class);List<ResultType> results = result.getMappedResults();```8. 排序:```Query query = new Query().with(Sort.by(Sort.Direction.DESC, "field"));List<T> results = mongoTemplate.find(query, T.class, collectionName);```9. 查询总数:```Long count = mongoTemplate.count(query, collectionName); ```以上是MongoTemplate的一些常用操作,可根据具体业务需求进行调整和组合使用。
MongoDB的基本使用方法

MongoDB的基本使用方法MongoDB是一种NoSQL数据库,它非常适合处理大量结构松散的数据。
相较于传统的关系型数据库,它更加灵活,易于扩展。
本文将分为以下几个章节,介绍MongoDB的基本使用方法。
一、安装MongoDBMongoDB的官方网站提供了多种操作系统的安装包,用户可以选择适合自己的版本进行下载。
安装完成之后,需要配置MongoDB的环境变量,方便在终端中直接使用MongoDB命令。
二、启动MongoDB在终端输入"mongod"命令来启动MongoDB,并且默认会使用"/data/db"作为默认数据存储路径。
如果需要修改默认的数据存储路径,可以在启动时添加"--dbpath"参数,例如"mongod --dbpath/user/local/mongodb_data"。
三、连接MongoDB在终端中输入"mongo"命令可以进行与MongoDB的连接,并且默认连接到本地的MongoDB。
如果需要连接到远程的MongoDB,需要通过"mongo host:port"命令进行连接,其中host为MongoDB的IP地址,port为其端口号。
四、数据的增删改查MongoDB是一种文档型数据库,其数据以文档形式进行存储。
一条文档就是一个键值对集合,文档可以包含嵌套的文档,以及数组类型的值。
MongoDB提供了丰富的CRUD操作来实现数据的增删改查。
1.插入数据MongoDB中,可以通过insert()或者save()方法来插入一条数据。
例如:ers.insert({name:"Tom",age:18});或者:ers.save({_id:1,name:"Tom",age:18});其中,insert()和save()操作的区别在于,当插入数据的唯一标识已经存在时,insert()方法会直接报错,而save()方法则会将数据替换。
MongoDB数据库入门教程

MongoDB数据库入门教程作为一款非关系型的分布式数据库,MongoDB备受广大开发者的喜爱。
它不仅提供了高性能的数据处理和存储服务,而且还具有灵活的数据结构以及强大的查询语言等特点。
如果你也想拥有这样一个全能型的数据库,那么接下来的MongoDB数据库入门教程将会为你提供实用的知识和技能。
一、安装MongoDB在学习MongoDB之前,你需要先进行安装和配置。
可以通过官方网站下载相应的安装程序,然后进行简单的操作即可完成安装。
此外,还需要设置环境变量等相关配置,以确保在使用时的正常运行。
二、建立数据库创建数据库是MongoDB的第一步,这里以“school”为例,讲解如何建立一个数据库。
在CMD命令行中输入“mongod”命令,并通过“mongo”命令进入命令行终端,使用以下命令建立“school”数据库。
> use school三、建立集合集合是数据组织的最基本单位,可以看作是表的概念。
在MongoDB中,集合可以无限制地扩展,不需要提前设置结构,非常灵活。
我们可以通过以下命令创建一个“students”集合。
> db.createCollection(\"students\")四、插入文档把文档插入到集合中是MongoDB中最简单、最常见的操作之一。
MongoDB 的文档是以键值对的形式计数的,这里以学生作为一个文档进行插入,使用以下命令插入一个学生的信息。
> db.students.insert({name:\"Tom\",age:18,gender:\"male\"})五、查询文档MongoDB提供了丰富的查询语言,可以满足各种查询需求。
这里以查询年龄为18岁的学生的信息为例。
> db.students.find({age:18})六、更新文档MongoDB可以对集合中的文档进行更新,具体实现可以使用update()函数。
java中mongodb用法

java中mongodb用法Java中MongoDB是一种非关系型数据库,也被广泛应用于各种项目之中。
本文将详细介绍Java中MongoDB的用法,主要包括MongoDB的安装、配置、连接、查询、更新等操作。
1. 安装MongoDB首先,我们需要在本地环境中安装MongoDB。
具体安装过程可以参考MongoDB官方文档,包括解压下载的MongoDB安装包、配置环境变量等步骤。
安装完成后,我们可以通过命令行输入`mongo`命令,进入MongoDB的shell环境。
2. 配置MongoDB在Java中使用MongoDB之前,我们需要配置MongoDB的连接信息。
在Java中,我们可以使用Java驱动程序提供的`MongoClient`类来与MongoDB建立连接。
以下是一个示例的连接配置:import com.mongodb.MongoClient;import com.mongodb.MongoClientURI;public class MongoDBJavaExample {public static void main(String[] args) {MongoClientURI uri = newMongoClientURI("mongodb:localhost:27017");MongoClient mongoClient = new MongoClient(uri);连接到指定的数据库MongoDatabase database =mongoClient.getDatabase("mydb");连接到指定的集合MongoCollection<Document> collection = database.getCollection("mycollection");其他操作...}}在上面的示例中,我们通过`MongoClientURI`类来指定MongoDB的连接URI字符串,在本例中我们连接到本地的MongoDB实例,端口号为默认的27017。
请列举几个常用的mongodb操作命令

请列举几个常用的mongodb操作命令
1. 插入数据命令
`db.collection.insertOne(document)`:向指定的集合中插入一个文档。
2. 查询数据命令
`db.collection.find(query, projection)`:查询指定集合中符合条件的文档。
3. 更新数据命令
`db.collection.updateOne(filter, update, options)`:更新指定集合中符合条件的第一个文档。
4. 删除数据命令
`db.collection.deleteOne(filter)`:删除指定集合中符合条件的第一个文档。
5. 创建索引命令
`db.collection.createIndex(keys, options)`:在指定集合中创建索引。
6. 聚合数据命令
`db.collection.aggregate(pipeline)`:执行聚合操作,根据指定条件对数据进行聚合操作。
7. 删除集合命令
`db.collection.drop()`:删除指定集合及其所有文档。
8. 查看集合命令
`show collections`:显示当前数据库中的所有集合。
9. 切换数据库命令
`use database`:切换当前使用的数据库到指定数据库。
10. 查看数据库列表命令
`show dbs`:显示当前MongoDB服务器上的所有数据库。
请注意,以上命令中的"collection"和"database"需要替换为实际使用的集合和数据库名称。
mongodb shell基本操作及数据查询实验原理

mongodb shell基本操作及数据查询实验原理MongoDB Shell 是一个基于JavaScript 的交互式工具,用于与MongoDB 数据库进行交互。
它提供了一系列基本操作,如数据库、集合和文档的增删改查等。
下面将介绍一些MongoDB Shell 的基本操作及数据查询实验原理。
1. 连接MongoDB 数据库在开始操作之前,首先需要连接到MongoDB 数据库。
在命令行中输入以下命令:```javascriptmongo```这将连接到默认的MongoDB 实例,即localhost:27017。
2. 创建数据库使用`use` 命令可以创建一个新的数据库。
例如,创建一个名为"test" 的数据库:```javascriptuse test```3. 显示所有数据库输入以下命令可以查看当前连接的所有数据库:```javascriptshow dbs```4. 创建集合使用`db.collection()` 方法可以创建一个新的集合。
例如,创建一个名为"users" 的集合:```javascripters.insert({ name: "John", age: 30 })```5. 插入文档使用`insert` 方法可以向集合中插入文档。
例如,插入一个包含名字和年龄的文档:```javascripters.insert({ name: "Alice", age: 25 })```6. 查询数据使用`find` 方法可以查询集合中的数据。
例如,查询年龄大于等于20 的所有用户:```javascripters.find({ age: { $gte: 20 } })```7. 更新数据使用`update` 方法可以更新集合中的文档。
例如,更新名字为"Bob" 的用户的年龄为35:```javascripters.update({ name: "Bob" }, { age: 35 })```8. 删除数据使用`remove` 方法可以删除集合中的文档。
mongodb实验数据库基本操作

mongodb实验数据库基本操作MongoDB是一种非关系型数据库,它以文档的形式存储数据。
在本文中,我们将介绍MongoDB实验数据库的基本操作。
首先,我们需要安装MongoDB并启动它。
安装过程可以参考MongoDB官方网站提供的文档。
安装完成后,我们可以通过命令行或者MongoDB的图形界面工具来操作数据库。
接下来,我们需要创建一个数据库。
在MongoDB中,可以使用`use`命令来创建数据库。
例如,我们可以使用以下命令创建一个名为`experiment`的数据库:```use experiment```创建数据库后,我们可以使用`db`命令来查看当前正在使用的数据库。
例如,我们可以使用以下命令查看当前正在使用的数据库:```db```接下来,我们可以创建一个集合(类似于关系型数据库中的表)。
在MongoDB中,可以使用`db.createCollection()`命令来创建集合。
例如,我们可以使用以下命令创建一个名为`students`的集合:```db.createCollection("students")```创建集合后,我们可以使用`db.getCollectionNames()`命令来查看当前数据库中的所有集合。
例如,我们可以使用以下命令查看当前数据库中的所有集合:```db.getCollectionNames()```接下来,我们可以向集合中插入文档(类似于关系型数据库中的行)。
在MongoDB中,可以使用`db.collection.insert()`命令来插入文档。
例如,我们可以使用以下命令向`students`集合中插入一个名为`Alice`的文档:```db.students.insert({name: "Alice", age: 20, major: "Computer Science"}) ```插入文档后,我们可以使用`db.collection.find()`命令来查询集合中的文档。
mongodb数组操作

mongodb数组操作在MongoDB中,可以使用多种操作来处理数组。
以下是一些常见的数组操作:1. 查询数组元素:使用`$elemMatch`操作符可以查询满足指定条件的数组元素。
例如,`db.collection.find({arrayField: {$elemMatch: {field: value}}})`将返回包含满足条件的数组元素的文档。
2. 更新数组元素:使用`$set`操作符可以更新数组中指定位置的元素。
例如,`db.collection.update({arrayField: {$elemMatch: {field: value}}}, {$set: {"arrayField.$.field": newValue}})`会将满足条件的数组元素的字段更新为新的值。
3. 添加数组元素:使用`$push`操作符可以向数组中添加元素。
例如,`db.collection.update({_id: documentId}, {$push: {arrayField: element}})`会将指定元素添加到数组中。
4. 删除数组元素:使用`$pull`操作符可以从数组中删除满足指定条件的元素。
例如,`db.collection.update({_id: documentId}, {$pull: {arrayField: {field: value}}})`会从数组中删除满足条件的元素。
5. 数组过滤:使用`$filter`操作符可以根据指定条件筛选数组中的元素。
例如,`db.collection.aggregate([{$project: {filteredArray: {$filter: {input: "$arrayField", as: "element", cond: {$gte: ["$$element.field", value]}}}}}}])`会返回满足条件的数组元素。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
撰写报告实验名称:课程名称:实验学期:班级名称:学生姓名:学生学号:上课地点:实验时间:截止时间:实验目的:实验指导书:实验内容:一、数据库操作1.显示当前选择的数据库> dbtest2.创建或切换数据库MyDB> use MyDBswitched to db MyDB> dbMyDB3.查看所有数据库> show dbslocal 0.078GB4.向MyDB插入一个文件> db.movie.insert({"name":"tutorials yiibai"}) WriteResult({ "nInserted" : 1 })5.查看所有数据库> show dbsMyDB 0.078GBlocal 0.078GB6.删除数据库MyDB> db.dropDatabase(){ "dropped" : "MyDB", "ok" : 1 }> show dbslocal 0.078GB二、集合操作1.显式和隐式创建集合movie显示集合创建> db.createCollection("movie"){ "ok" : 1 }> show collectionsmoviesystem.indexes隐身集合创建> db.movie.insert({"name":"tutorials yiibai"})WriteResult({ "nInserted" : 1 })> show collectionsmoviesystem.indexes2.查询所有集合> show collectionsmoviesystem.indexes3.查看集合总数据量> db.movie.count()14.查看movie集合所在数据库> db.movie.getDB()MyDB5.查看当前集合movie状态> db.movie.stats(){"ns" : "MyDB.movie","count" : 1,"size" : 112,"avgObjSize" : 112,"numExtents" : 1,"storageSize" : 8192,"lastExtentSize" : 8192,"paddingFactor" : 1,"paddingFactorNote" : "paddingFactor is unused and unmaintained in 3.0. It remains hard coded to 1.0 for compatibility only.","userFlags" : 1,"capped" : false,"nindexes" : 1,"totalIndexSize" : 8176,"indexSizes" : {"_id_" : 8176},"ok" : 1}6.集合movie重命名> db.movie.renameCollection("movies"){ "ok" : 1 }> show collectionsmoviessystem.indexes7.集合movie复制> db.movies.copyTo("movie")1> show collectionsmoviemoviessystem.indexes8.删除集合movie> db.movie.drop()true> show collectionsmoviessystem.indexes9.查看集合movie帮助> db.movies.help()DBCollection helpdb.movies.find().help() - show DBCursor helpdb.movies.count()db.movies.copyTo(newColl) - duplicates collection by copying all documents to newColl; no indexes are copied.db.movies.convertToCapped(maxBytes) - calls {convertToCapped:'movies', size:maxBytes}} commanddb.movies.dataSize()db.movies.distinct( key ) - e.g. db.movies.distinct( 'x' )db.movies.drop() drop the collectiondb.movies.dropIndex(index) - e.g. db.movies.dropIndex( "indexName" ) or db.movies.dropIndex( { "indexKey" : 1 } )db.movies.dropIndexes()db.movies.ensureIndex(keypattern[,options])db.movies.explain().help() - show explain helpdb.movies.reIndex()db.movies.find([query],[fields]) - query is an optional query filter. fields is optional set of fields to return.e.g. db.movies.find( {x:77} , {name:1, x:1} )db.movies.find(...).count()db.movies.find(...).limit(n)db.movies.find(...).skip(n)db.movies.find(...).sort(...)db.movies.findOne([query])db.movies.findAndModify( { update : ... , remove : bool [, query: {}, sort: {}, 'new': false] } )db.movies.getDB() get DB object associated with collectiondb.movies.getPlanCache() get query plan cache associated with collectiondb.movies.getIndexes()db.movies.group( { key : ..., initial: ..., reduce : ...[, cond: ...] } ) db.movies.insert(obj)db.movies.mapReduce( mapFunction , reduceFunction , <optional params> ) db.movies.aggregate( [pipeline], <optional params> ) - performs an aggregation on a collection; returns a cursordb.movies.remove(query)db.movies.renameCollection( newName , <dropTarget> ) renames the collection.db.movies.runCommand( name , <options> ) runs a db command with the given name where the first param is the collection namedb.movies.save(obj)db.movies.stats({scale: N, indexDetails: true/false, indexDetailsKey: <index key>, indexDetailsName: <index name>})db.movies.storageSize() - includes free space allocated to this collection db.movies.totalIndexSize() - size in bytes of all the indexesdb.movies.totalSize() - storage allocated for all data and indexesdb.movies.update(query, object[, upsert_bool, multi_bool]) - instead of two flags, you can pass an object with fields: upsert, multidb.movies.validate( <full> ) - SLOWdb.movies.getShardVersion() - only for use with shardingdb.movies.getShardDistribution() - prints statistics about data distribution in the clusterdb.movies.getSplitKeysForChunks( <maxChunkSize> ) - calculates split points over all chunks and returns splitter functiondb.movies.getWriteConcern() - returns the write concern used for any operations on this collection, inherited from server/db if setdb.movies.setWriteConcern( <write concern doc> ) - sets the write concern for writes to the collectiondb.movies.unsetWriteConcern( <write concern doc> ) - unsets the write concern for writes to the collection三、文档操作1.插入操作a.向集合movie中分别插入下列文档,并观察集合结构db.movie.insert({"name":"HuanLeSong","Times":10000})db.movie.insert({"name":"SanJie","Times":20000})db.movie.insert({"name":"SanJie","Address":"China"})db.movie.find()> db.movie.insert({"name":"HuanLeSong","Times":10000})WriteResult({ "nInserted" : 1 })> movieVar2 = {"name":"SanJie","Times":20000};{ "name" : "SanJie", "Times" : 20000 }> movieVar3 = {"name":"SanJie","Address":"China"};{ "name" : "SanJie", "Address" : "China" }> db.movie.find(){ "_id" : ObjectId("57503fd0af6dafef3d9ac421"), "name" : "tutorials yiibai" } { "_id" : ObjectId("57504012af6dafef3d9ac422"), "name" : "HuanLeSong", "Times" : 10000 }插入数据> db.movie.insert({"_id":08001,"name":"zhangsan"})WriteResult({ "nInserted" : 1 })> db.movie.find(){ "_id" : ObjectId("57503fd0af6dafef3d9ac421"), "name" : "tutorials yiibai" } { "_id" : ObjectId("57504012af6dafef3d9ac422"), "name" : "HuanLeSong", "Times" : 10000 }{ "_id" : 8001, "name" : "zhangsan" }> db.movie.save({"_id":08001,"name":"lisi"})WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })> db.movie.find(){ "_id" : ObjectId("57503fd0af6dafef3d9ac421"), "name" : "tutorials yiibai" } { "_id" : ObjectId("57504012af6dafef3d9ac422"), "name" : "HuanLeSong", "Times" : 10000 }{ "_id" : 8001, "name" : "lisi" }采用数组的方式 []>db.movie.insert([{username:'aaa',password:'bbb',tel:'123123123'},{username:'bb b',password:'ccc',tel:'123123234'}]);BulkWriteResult({"writeErrors" : [ ],"writeConcernErrors" : [ ],"nInserted" : 2,"nUpserted" : 0,"nMatched" : 0,"nModified" : 0,"nRemoved" : 0,"upserted" : [ ]})> db.movie.find(){ "_id" : ObjectId("57503fd0af6dafef3d9ac421"), "name" : "tutorials yiibai" } { "_id" : ObjectId("57504012af6dafef3d9ac422"), "name" : "HuanLeSong", "Times" : 10000 }{ "_id" : 8001, "name" : "lisi" }{ "_id" : ObjectId("57504306af6dafef3d9ac423"), "username" : "aaa", "password" : "bbb", "tel" : "123123123" }{ "_id" : ObjectId("57504306af6dafef3d9ac424"), "username" : "bbb", "password" : "ccc", "tel" : "123123234" }删除操作(1)按条件进行删除> db.movie.remove({"name":"HuanLeSong"});WriteResult({ "nRemoved" : 1 })> db.movie.find(){ "_id" : ObjectId("57503fd0af6dafef3d9ac421"), "name" : "tutorials yiibai" } { "_id" : 8001, "name" : "lisi" }{ "_id" : ObjectId("57504306af6dafef3d9ac423"), "username" : "aaa", "password" : "bbb", "tel" : "123123123" }{ "_id" : ObjectId("57504306af6dafef3d9ac424"), "username" : "bbb", "password" : "ccc", "tel" : "123123234" }(2)删除所有[用remove删除]> db.movie.remove({})WriteResult({ "nRemoved" : 4 })> db.movie.find()> show collectionsmovieSystem.indexes[用drop删除]>db.movie.insert([{username:'aaa',password:'bbb',tel:'123123123'},{username:'bb b',password:'ccc',tel:'123123234'}]);BulkWriteResult({"writeErrors" : [ ],"writeConcernErrors" : [ ],"nInserted" : 2,"nUpserted" : 0,"nMatched" : 0,"nModified" : 0,"nRemoved" : 0,"upserted" : [ ]})> db.movie.find(){ "_id" : ObjectId("575044fcaf6dafef3d9ac425"), "username" : "aaa", "password" : "bbb", "tel" : "123123123" }{ "_id" : ObjectId("575044fcaf6dafef3d9ac426"), "username" : "bbb", "password" : "ccc", "tel" : "123123234" }> db.movie.drop()true> show collectionssystem.indexes修改操作> db.movie.find(){ "_id" : ObjectId("575048d9af6dafef3d9ac427"), "username" : "aaa", "password" : "bbb", "tel" : "123123123" }{ "_id" : ObjectId("575048d9af6dafef3d9ac428"), "username" : "bbb", "password" :"ccc", "tel" : "123123234" }> db.movie.update({username:"bbb"},{password:"abc"});WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })> db.movie.find(){ "_id" : ObjectId("575048d9af6dafef3d9ac427"), "username" : "aaa", "password" : "bbb", "tel" : "123123123" }{ "_id" : ObjectId("575048d9af6dafef3d9ac428"), "password" : "abc" }$set修改器> db.movie.update({username:"aaa"},{$set:{password:"*****"}});WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })> db.movie.find(){ "_id" : ObjectId("575048d9af6dafef3d9ac427"), "username" : "aaa", "password" : "*****", "tel" : "123123123" }{ "_id" : ObjectId("575048d9af6dafef3d9ac428"), "password" : "abc" }$unset修改器> db.movie.update({username:"aaa"},{$unset:{tel:1}});WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })> db.movie.find(){ "_id" : ObjectId("575048d9af6dafef3d9ac427"), "username" : "aaa", "password" : "*****" }{ "_id" : ObjectId("575048d9af6dafef3d9ac428"), "password" : "abc" }.$inc修改器> db.movie.update({username:"aaa"},{$inc:{age:2}});WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })> db.movie.find(){ "_id" : ObjectId("575048d9af6dafef3d9ac427"), "username" : "aaa", "password" : "*****", "age" : 2 }{ "_id" : ObjectId("575048d9af6dafef3d9ac428"), "password" : "abc" }在原基础上age+2> db.movie.update({username:'aaa'},{$inc:{age:2}});WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })> db.movie.find(){ "_id" : ObjectId("575048d9af6dafef3d9ac427"), "username" : "aaa", "password" : "*****", "age" : 4 }{ "_id" : ObjectId("575048d9af6dafef3d9ac428"), "password" : "abc" }Upsert 的用法 --当没有文档符合更新条件,就会以这个条件创建新的文档> db.movie.update({username:'aaa'},{$set:{abc:123}},true)WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })> db.movie.find(){ "_id" : ObjectId("575048d9af6dafef3d9ac427"), "username" : "aaa", "password" : "*****", "age" : 4, "abc" : 123 }{ "_id" : ObjectId("575048d9af6dafef3d9ac428"), "password" : "abc" }当文档符合更新条件,就会更新文档> db.movie.update({username:'aaa'},{$set:{abc:234}},true)WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })> db.movie.find(){ "_id" : ObjectId("575048d9af6dafef3d9ac427"), "username" : "aaa", "password" : "*****", "age" : 4, "abc" : 234 }{ "_id" : ObjectId("575048d9af6dafef3d9ac428"), "password" : "abc" }实验步骤与调试过程:实验结果:疑难小结:在进行查看当前集合状态的时候输出的结果有点不是很明白在插入数值时我们会发现如果插入的集合的“_id”值,在集合中已经存在则在插入_id是的值会报错出现错误。