2
我試圖創建一個MongoDB的集合類似於組查詢:集團在rmongodb
db.orders.group({
key: { ord_dt: 1, 'item.sku': 1 },
cond: { ord_dt: { $gt: new Date('01/01/2012') } },
reduce: function (curr, result) { },
initial: { }
})
我使用rmongodb。從去的rmongodb包文檔了,他們用mongo.command
運行計數命令:
mongo <- mongo.create()
if (mongo.is.connected(mongo)) {
buf <- mongo.bson.buffer.create()
mongo.bson.buffer.append(buf, "count", "people")
mongo.bson.buffer.append(buf, "query", mongo.bson.empty())
command <- mongo.bson.from.buffer(buf)
result = mongo.command(mongo, "test", command)
if (!is.null(result)) {
iter = mongo.bson.find(result, "n") print(mongo.bson.iterator.value(iter))
}
}
也不同:
mongo.distinct <- function(mongo, db, collection, key) {
b <- mongo.command(mongo, db, list(distinct=collection, key=key))
if(!is.null(b))
b <- mongo.bson.value(b, "values")
}
names <- mongo.distinct(mongo, "test", "people", "name")
有沒有人有使用mongo.command
做一組查詢成功?