获取类似结果的 MongoDB 运算符 $eq 的替代方法
要编写等号,你可以直接使用 find() 和 match 值。让我们创建一个带文档的集合 -
> db.demo145.insertOne({"ListOfNames":["Chris","David","Mike"]});
{
"acknowledged" : true,
"insertedId" : ObjectId("5e32f37bfdf09dd6d08539bb")
}
> db.demo145.insertOne({"ListOfNames":["Bob","John"]});
{
"acknowledged" : true,
"insertedId" : ObjectId("5e32f384fdf09dd6d08539bc")
}使用 find() 方法显示集合中的所有文档 -
> db.demo145.find();
这将产生以下输出 -
{ "_id" : ObjectId("5e32f37bfdf09dd6d08539bb"), "ListOfNames" : [ "Chris", "David", "Mike" ] }
{ "_id" : ObjectId("5e32f384fdf09dd6d08539bc"), "ListOfNames" : [ "Bob", "John" ] }以下是实现 MongoDB 运算符 $eq 的查询 -
> db.demo145.find({"ListOfNames":"John"});这将产生以下输出 -
{ "_id" : ObjectId("5e32f384fdf09dd6d08539bc"), "ListOfNames" : [ "Bob", "John" ] }
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP