Olivine-Labs / resty-mongol

Lua MongoDB driver
MIT License
46 stars 23 forks source link

BSON field 'OperationSessionInfo.aggregate' is a duplicate field #16

Open alexz006 opened 4 years ago

alexz006 commented 4 years ago

How to use "aggregate"?

local mongol = require "resty-mongol"
local conn = mongol()
conn:connect('127.0.0.1', 27017)
local db = conn:new_db_handle ("test")
local col = db:get_col("test")

col:drop()

col:insert({
    {_id = 1, type = "cat", weight = 15},
    {_id = 2, type = "cat", weight = 10},
    {_id = 3, type = "cat", weight = 8.5},
    {_id = 4, type = "dog", weight = 15},
    {_id = 5, type = "dog", weight = 20},
})

local out = {}
local cursor = col:find{}
for i, item in cursor:pairs() do
    out[i] = item
end
--[[
out = [{"_id":1,"weight":15,"type":"cat"},{"_id":2,"weight":10,"type":"cat"},{"_id":3,"weight":8.5,"type":"cat"},{"_id":4,"weight":15,"type":"dog"},{"_id":5,"weight":20,"type":"dog"}]
]]

local n, err = col:aggregate({
    { ['$sort'] = {_id = -1} }
})
--[[
n = null
err = "BSON field 'OperationSessionInfo.aggregate' is a duplicate field"
]]

MongoDB server version: 4.2.2