不使用 $eq 运算符在 MongoDB 中编写等式
我们先创建一个文档集合 -
> 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" ] }
广告