Mongolian or Mongolian not supported group function?

Guys

In node.js, mongolian or mongo-native group function is not supported?

mongo-native code,

var mongodb = require('mongodb'); var Db = mongodb.Db; var Server = mongodb.Server; var db = new Db( "test", new Server( "localhost", 27017 ), { w:0 } ); db.collection( "user" ).group( { key: { }, reduce: function ( curr, result ) { }, initial: { } } ); 

result

 /node/ex1/node_modules/mongodb/lib/mongodb/collection.js:1400 if(err != null) return callback(err); ^ TypeError: undefined is not a function at Collection.group.scope (/node/ex1/node_modules/mongodb/lib/mongodb/collection.js:1400:30) at Db._executeQueryCommand (/node/ex1/node_modules/mongodb/lib/mongodb/db.js:1812:12) at Collection.group (/node/ex1/node_modules/mongodb/lib/mongodb/collection.js:1399:13) at Object.<anonymous> (/node/ex1/repository.js:34:25) 

and mongolign code,

 var Mongolian = require( "mongolian" ); var server = new Mongolian; var db = server.db( "test" ); db.collection( "user" ).group( { key: { }, reduce: function ( curr, result ) { }, initial: { } } ); 

result

 db.collection( "user" ).group( { ^ TypeError: Object Mongolian[mongo://localhost:27017]/assistor.user has no method 'group' at Object.<anonymous> (/node/ex1/repository.js:77:25) 
+1
source share
2 answers

As you can see from the documents , it is supported by the native driver, but the group method accepts key , reduce , etc. as separate parameters instead of fields in an object such as a shell:

 db.collection("user").group( {}, {}, { sum: 0 }, function (curr, result) { }, function (err, result) { // Process the result } ); 
+3
source

The Mongolian package in npm is not updated, you have to clone the git repository and then link it to npm.

Then the documentation is not complete, you need to do something like this, it took me a while to get it working.

 var Mongolian = require( "mongolian" ); var server = new Mongolian; var db = server.db( "test" ); db.collection( "user" ).group( { ns: "user", key: { }, reduce: function ( curr, result ) { }, initial: { } },function(error,post){ if(error) console.log(error); //do something with post.retval } ); 
0
source

Source: https://habr.com/ru/post/1216256/


All Articles