You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
How to use "aggregate"?
MongoDB server version: 4.2.2
The text was updated successfully, but these errors were encountered: