Вы находитесь на странице: 1из 1

MongoDB Search

By default, MongoDB queries for an OR of all the words: ask OR hn. This is the most
efficient way to perform a full text query, but you can also do exact phrase searches and
NOT. To search for the exact phrase ask hn, you can query for that by including the
query in quotes:
> db.runCommand({text: "hn", search: "\"ask hn\""})
{
"queryDebugString" : "ask|hn||||ask hn||",
"language" : "english",
"results" : [
{
"score" : 2.25,
"obj" : {
"_id" : ObjectId("50dcab296803fa7e4f000011"),
"title" : "Ask HN: Most valuable skills you have?",
"url" : "/comments/4974230",
"id" : 4974230,
"commentCount" : 37,
"points" : 31,
"postedAgo" : "2 hours ago",
"postedBy" : "bavidar"
}
}
],
"stats" : {
"nscanned" : 4,
"nscannedObjects" : 0,
"n" : 1,
"nfound" : 1,
"timeMicros" : 20392
},
"ok" : 1
}
This is slower than the OR-type match, since MongoDB first performs an OR match
and then post-processes the documents to ensure that they are AND matches, as well.
You can also make part of a query literal and part not:
> db.runCommand({text: "hn", search: "\"ask hn\" ipod"})
This will search for exactly "ask hn" and, optionally, "ipod".
You can also search for not including a certain string by using "-":
> db.runCommand({text: "hn", search: "-startup vc"})

Вам также может понравиться