让我们首先创建包含文档的集合-
> db.operatorDemo.insertOne({"StudentSubject":["MongoDB","MySQL","Java"]}); { "acknowledged" : true, "insertedId" : ObjectId("5cef94eaef71edecf6a1f6a2") } > db.operatorDemo.insertOne({"StudentSubject":["Java","C","C++"]}); { "acknowledged" : true, "insertedId" : ObjectId("5cef94faef71edecf6a1f6a3") }
在find()
方法的帮助下显示集合中的所有文档-
> db.operatorDemo.find().pretty();
输出结果
{ "_id" : ObjectId("5cef94eaef71edecf6a1f6a2"), "StudentSubject" : [ "MongoDB", "MySQL", "Java" ] } { "_id" : ObjectId("5cef94faef71edecf6a1f6a3"), "StudentSubject" : [ "Java", "C", "C++" ] }
以下是不带$eq运算符的相等查询:
> db.operatorDemo.find({StudentSubject:"MongoDB"});
输出结果
{ "_id" : ObjectId("5cef94eaef71edecf6a1f6a2"), "StudentSubject" : [ "MongoDB", "MySQL", "Java" ] }