在mongodb集合中查找字段等于给定整数值的文档?
要查找其中一个字段等于给定整数的文档,请使用find()。我们使用文档创建一个集合−
> db.demo472.insertOne({"Project_Id":-101,"ProjectName":"Online Customer Tracking"});{
"acknowledged" : true,
"insertedId" : ObjectId("5e80586cb0f3fa88e227907a")
}
> db.demo472.insertOne({"Project_Id":101,"ProjectName":"Online Banking System"});{
"acknowledged" : true,
"insertedId" : ObjectId("5e805884b0f3fa88e227907b")
}
> db.demo472.insertOne({"Project_Id":102,"ProjectName":"Online Library System"});{
"acknowledged" : true,
"insertedId" : ObjectId("5e805893b0f3fa88e227907c")
}使用find()方法从集合中显示所有文档−
> db.demo472.find();
这将产生以下输出−
{ "_id" : ObjectId("5e80586cb0f3fa88e227907a"), "Project_Id" : -101, "ProjectName" : "Online
Customer Tracking" }
{ "_id" : ObjectId("5e805884b0f3fa88e227907b"), "Project_Id" : 101, "ProjectName" : "Online
Banking System" }
{ "_id" : ObjectId("5e805893b0f3fa88e227907c"), "Project_Id" : 102, "ProjectName" : "Online
Library System" }以下是查找MongoDB集合中其中一个字段等于给定整数的文档的查询−
> db.getCollection('demo472').find({"Project_Id":-101});这将产生以下输出−
{ "_id" : ObjectId("5e80586cb0f3fa88e227907a"), "Project_Id" : -101, "ProjectName" : "Online
Customer Tracking" }
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C编程
C++
C#
MongoDB
MySQL
Javascript
PHP