Jak wyjaśnić odrębne zapytanie w MongoDB?Jak wyjaśnić oddzielne zapytanie w MongoDB?
db.test3.distinct("id", { key:"value"}).explain()
Błędy z:
explain is not a function (shell)
Jak wyjaśnić odrębne zapytanie w MongoDB?Jak wyjaśnić oddzielne zapytanie w MongoDB?
db.test3.distinct("id", { key:"value"}).explain()
Błędy z:
explain is not a function (shell)
Nie można korzystać z odrębną wyjaśnić, jak na tym MongoDB jira ticket. Zamiast tego można użyć runCommand
i weryfikacji statystyk, które jest trochę podobna do explain()
db.runCommand({ distinct: 'test3',key:'id',query:{key:"value"}})
W powyższym test3 zapytań jest nazwa kolekcji, kluczem jest nazwa pola chcesz zastosować odrębne i wreszcie jeśli chciał podać dowolny filtry używają zapytania.
Sprawdź próbki
> db.runCommand({ distinct: 'items',key:'name',query:{offered:true}})
{
"values" : [
"test flat",
"Another aston martin",
"super luxury villa",
"Aston martin vanquish y for sale",
"Super car",
"Test item",
"another sports car",
"super car"
],
"stats" : {
"n" : 8,
"nscanned" : 10,
"nscannedObjects" : 10,
"timems" : 45,
"cursor" : "BasicCursor"
},
"ok" : 1
}
> db.runCommand({ distinct: 'items',key:'name',query:{offered:false}})
{
"values" : [
"yamaha",
"Test item"
],
"stats" : {
"n" : 2,
"nscanned" : 10,
"nscannedObjects" : 10,
"timems" : 0,
"cursor" : "BasicCursor"
},
"ok" : 1
}
dzień Mongo 3.2, można to zrobić:
db.test3.explain().distinct("id", {key: "value"})
https://docs.mongodb.org/manual/reference/method/db.collection.explain/
Dzięki! Działa to doskonale dla mnie. –
Nie widzę statystyk, po prostu zwracam wartości i ok jako odpowiedź. – genericuser
@RyanHoffman: Powinien być oznaczony jako zaakceptowana odpowiedź, IMHO. Dzięki! –