【发布时间】:2018-05-01 15:42:22
【问题描述】:
Nodejs
dbo.collection("abc")
.find({"name": "Felicity"})
.sort({_id:-1})
.limit()
.exec(
function(err, results){
// my code
}
);
集合中的数据
cansOne = [
{
"_id": ObjectId("5ace23558980..."),
"name": "Khalichi",
"gender": "F",
"type":"Admin"
},
.
.
.
{
"_id": ObjectId("5ace23558980..."),
"name": "Thore",
"gender": "M",
"type":""
},
{
"_id": ObjectId("5ace23558980..."),
"name": "John Snow",
"gender": "M",
"type":"Admin"
},
{
"_id": ObjectId("5ace23558980..."),
"name": "Felicity",
"gender": "F",
"type":"User"
}
]
cansTwo = [
{
"_id": ObjectId("5ace23558980..."),
"name": "Khalichi",
"gender": "F",
"type":"Admin"
},
.
.
.
{
"_id": ObjectId("5ace23558980..."),
"name": "Thore",
"gender": "M",
"type":""
},
{
"_id": ObjectId("5ace23558980..."),
"name": "John Snow",
"gender": "M",
"type":"Admin"
},
{
"_id": ObjectId("5ace23558980..."),
"name": "Felicity",
"gender": "F",
"type":"User"
}
{
"_id": ObjectId("5ace23558980..."),
"name": "Batman",
"gender": "M",a
"type":""
}
]
我收集了这种类型的数据。有两种情况:
1) "type":"" 在集合结束时,表示它是集合的最后一个文档。
2) 在"type":"" 文档之后,有一些文档在集合中。
我想搜索一个文档,但如果它在 "type":"" 文档的最后一个索引之后,那么它将返回该文档,否则它将返回 null。简而言之,我想在最后一个 "type":"" 之后的那些数据量中搜索这条记录
谁能帮忙。
提前致谢。
例如我要搜索"name": "Felicity"。
预期输出
caseOne = [
{
"_id": ObjectId("5ace23558980..."),
"name": "Felicity",
"gender": "F",
"type":"User"
}
]
caseTwo = []
【问题讨论】:
-
嗨维普尔;我可以问一下您在考虑的集合的顺序吗?因为如果您依赖于特定记录是否在另一条记录之后,这取决于您使用什么顺序列出文档。