Come si spiega una query distinta in MongoDB?Come spieghi una query distinta in MongoDB?
db.test3.distinct("id", { key:"value"}).explain()
errori con:
explain is not a function (shell)
Come si spiega una query distinta in MongoDB?Come spieghi una query distinta in MongoDB?
db.test3.distinct("id", { key:"value"}).explain()
errori con:
explain is not a function (shell)
Non è possibile utilizzare spiegare con la distinta di cui al presente MongoDB jira ticket. Invece è possibile utilizzare runCommand
e verificare le statistiche, che è un pò simile a explain()
db.runCommand({ distinct: 'test3',key:'id',query:{key:"value"}})
In quanto sopra test3 query è nome della raccolta, chiave è un nome di campo che si desidera applicare distinti e, infine, se si voleva specificare qualsiasi i filtri utilizzano la query.
Controllare i campioni
> 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
}
Come di Mongo 3.2, si può fare:
db.test3.explain().distinct("id", {key: "value"})
https://docs.mongodb.org/manual/reference/method/db.collection.explain/
Grazie! Questo funziona alla grande per me. –
Non riesco a vedere le statistiche, torno solo ai valori e ok come risposta. – genericuser
@RyanHoffman: deve essere contrassegnato come risposta accettata, IMHO. Grazie! –