amark / mongous Goto Github PK
View Code? Open in Web Editor NEWSimple MongoDB driver for Node.js with jQuery like syntax.
License: MIT License
Simple MongoDB driver for Node.js with jQuery like syntax.
License: MIT License
Is there currently a way to provide an authenticated mongo connection using this driver? I did not immediately notice anything, but wanted to double check.
Hello, this query -> db.users.find({subscriptions:'electronics'}) works in a mongoose shell. 'subscriptions' is an array, and I'm returned all users who have the string 'electronics' in their 'subscriptions' array. However, using mongous, I've tried db('myapp.users').find({subscriptions:'electronics'}) and get back nothing. Does mongous not support the standard set of querying options provided by mongoDB?
Hello
I can haz npm version of mongous, please?
I'm trying to use .save() to update some existing records and it doesn't appear to work, though the function itself returns true. Any thoughts?
There is an existing user in the database that looks like this:
{name: 'GitHub User' , phone: '801-555-5555' , email: '[email protected]' , position: 'sr. gitmaster' , twitter: 'github' , pic: 'https://github.com/images/gravatars/gravatar-140.png' , yearsEmployed: '0' , _id: 'github-user-1299185222151' }
I want to add an @ in front of of his twitter name, so I try this with no luck:
mongous("mydb.users").save({name: 'GitHub User' , phone: '801-555-5555' , email: '[email protected]' , position: 'sr. gitmaster' , twitter: '@github' , pic: 'https://github.com/images/gravatars/gravatar-140.png' , yearsEmployed: '0' , _id: 'github-user-1299185222151' });
This doesn't seem to work, but from command line Mongo can do and it does update:
db.users.save({name: 'GitHub User' , phone: '801-555-5555' , email: '[email protected]' , position: 'sr. gitmaster' , twitter: '@github' , pic: 'https://github.com/images/gravatars/gravatar-140.png' , yearsEmployed: '0' , _id: 'github-user-1299185222151' });
Oh and I just figured out that this works as an alternative:
mongous("mydb.users").update({_id:user._id}, user);
I like the simplicity of mongous but I don't like how the database name is repeated.
The beauty (or "power") of something like mongodb-node-driver is that I can create a different connection in the unit tests so that I don't run tests on the same database as my development environment. If the database name is mentioned in the source code I'd have to refer to it as a variable each time. An active "variable" that is patchable when running tests.
So, how can I use mongous without having to say the name of the database in any more but one place?
For some reason when I do a find or any type of query that returns more than 100 records, it returns in the reply object:
"startingFrom":101 and only one object.
How do I get the previous results?
find method will trigger the callback function multiple times if there are more than 500 records. I think it's a bug.
in find:
if (msg.more && o.lim == 0) {
//lim = o.lim - it < 500 ? 500 : o.lim - it;
this.more(cmd.collectionName, 500, msg.cursorID, id);
} else {
con.c.removeListener(id.toString(), con.c.listeners(id.toString())[0]);
}
if (fn) {
return fn(msg);
}
I think it should be:
if (msg.more && o.lim == 0) {
//lim = o.lim - it < 500 ? 500 : o.lim - it;
this.more(cmd.collectionName, 500, msg.cursorID, id);
} else {
con.c.removeListener(id.toString(), con.c.listeners(id.toString())[0]);
if (fn) { /* move the callback inside the 'else' */
return fn(msg);
}
}
how do you think about it?
Hi there,
I'm new to Node and Mongo and mongous looks like exactly what I'd like to operate on my DB, except I can't figure out how to connect to it.
I'm hosting my DB with MongoHQ, how would I go about connecting to is using Mongous?
I've tried the following but it didn't work:
var $ = require("mongous").Mongous;
$().open("myhost.mongohq.com","12345").auth("myUserName","myPassword", function(reply){
console.log("Connected to MongoHQ!");
});
Is this possible using Mongous?
Thanks!
Hello amark,
Just wondering how to go about sorting since the only options I see are "lim" and "skip". Thanks!
Banx
Hi all,
Is there any easy way to remove the _ID from results?
Thanks
koti
Is it posible to have a callback/promise to test a result?
If no, any workaround?
Using getlasterror is not good enough fo async call.
i have a record like this: {"UserName":"Will","Sex":1}.
then i want to add a "Age" filed,then this record is like this:{"UserName":"Will","Sex":1,age:"30"}.
i can solve it like this : update({"UserName":"Will"},{"UserName":"Will","Sex":1,age:"30"}).
but this method ,must write all fieds.
In mongodb ,"update({"UserName":"Will"},{"$set" : {age:"30"}})" can add field.
Mongous can add field through similars method?
currently:
mongous.prototype.save = function(a) {
return this.update(a, a, 1);
};
I think shoud be so, I tested.
mongous.prototype.save = function(a) {
return this.update({a._id}, a, true);
};
The same as $set ... in update method
And i found that the find all operation return two collection while the data's length > 101.
I can't connect to the mongo server with the username and password
code like this:
$().open(host,port);
$('myDb.$cmd').auth(username,password);
which dosn't work
while i can connect to it successfully with mongodb://username:password@host:port/myDb with the mongo-native lib.
I can't find anything on mongous' error handling mechanism.
I dug through the code, but it's not exactly easy to read.
Could you please update the README or Wiki with how errors are handled,
and how mongous can be configured to e.g. set a custom mongo host, port,
auto-reconnect and that sort of stuff?
As far as I can tell errors are only logged, is that correct?
Sometimes the very first db('db.col').find(function(reply) {}) I do never calls the callback function.
For example:
var db = require('./mongous/mongous.js').Mongous;
db('db.col').find(function(reply) {
console.log('Reply: ' + reply);
});
If you run that by itself sometimes it will or will not return what you were looking for.
var $ = require("mongous").Mongous;
//var by={"_id" :$.ObjectID("5f732913000000f80c000002")};
var by={"_id" :"5f732913000000f80c000002"};
var record={"title" : "test", "url" : "www.google.com" };
$("db.tbl").update(by,record,function(err, updated){
console.log("update result");
console.log(err);
console.log(updated);
})
no output only echo
connecting...
connected!
findAndModify doesn't appear to be supported. Any plans for this?
Is there a means to make multi parameter queries in mongous?
i.e.
db.things.find( { x : 3, y : "foo" } );
Mongo Docs:
http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-Intro
Attribute node-mongodb-native author. :)
how can I get it?
Suppose this is my find query:
db('blog.users').find(function(reply){ }, {age: 25}, {})
How do I count the number of results ? From what I see db('blog.users').find(function(reply){ }, {age: 25}, {}).count() is not possible because there is not a .count() method...
Thanks in advance.
The sample code doesn't tell how to specify hostname and port number. It would be much helpful to have a complete example code.
Hi, great plugin, only one thing missing (i think): support for MongoDB's ObjectIDs(http://www.mongodb.org/display/DOCS/Object+IDs).
Will you be adding it anytime soon ?
Thanks in advance,
A lot of people
I try to query on _id, stored in ObjectId but query in string. It seems that the client could not support it, is that true?
remove command is not working after i upgrade mongous to the current version
But after downgrading mongous module to the older version, it is working now!
I am using node v0.6.2
Sorry i forgot to copy and paste the error message.
Koti
...doesn't seem to be working. I definitely have the ID correct - I set it to be an integer - but the following code fails to remove it:
db.remove({'_id': id});
Where the variable "id" is simply the ID. Any ideas?
I'm curious why use
Math.round(Math.exp(Math.random() * Math.log(100000)));
to generate id.
Is there any mathematical background behind the formula? or the 'net' module require an id like that?
after a few attempts, I thought this formula is not very good as an random id generator. It has much bigger chance to get a number between 1-10 than other numbers.
try this code in node:
for(var i=0;i<20;i++) { var t = Math.round(Math.exp(Math.random() * Math.log(100000))); console.log( t ); }
every time I executed the code, I could find numbers between 1-10.
That means if I send many requests to mongous in a short time, the id has a great chance to conflict and one request may trigger the callback which belongs to another request.
I am looking for a way to get the last inserted _id. It would be a nice api feature. Ideas? Thanks
How can I terminate the DB connection and all the instances of mongous functions?
I would like to see the database in connection optional. I like to be able to configure/set it up once, and have future commands use the same database, like so:
var $ = require("mongous").Mongous;
var c = nconf.get('database');
$().open(c.host,c.port);
$(c.database + '.$cmd').auth(c.user,c.pass,function(reply){
db('.people').find(1, {"fname": "Tom"}, function(reply){
console.log(reply);
});
});
.people
in this case would equal c.database + ".people"
I can sort of do this with var shorthand, but it seems just a tad clunky:
var $ = require("mongous").Mongous;
var c = nconf.get('database'), d = c.database;
$().open(c.host,c.port);
$(d + '.$cmd').auth(c.user,c.pass,function(reply){
db(d + '.people').find(1, {"fname": "Tom"}, function(reply){
console.log(reply);
});
});
You do not indicate which license is mongous distributed under, making it tricky to use.
Could you please assign any license to it? (BSD, MIT, GPL, commercial, ...)
Is it posible to create / drop /refresh index?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.