Questions tagged [mongojs]

MongoJS is a Node.js package to access MongoDB.

References:

306 questions
58
votes
2 answers

Get latest MongoDB record by field of datetime

I have a collection like this: { 'datetime': some-date, 'lat': '32.00', 'lon': '74.00' }, { 'datetime': some-date, 'lat': '32.00', 'lon': '74.00' } How can I get the latest record from MongoDB, where the datetime is the…
FarazShuja
  • 2,287
  • 2
  • 23
  • 34
27
votes
3 answers

Why do I need Mongoose or Mongojs for Node.js?

Major Questions Currently I'm very confused, the main questions are: What is the use of Mongoose/Mongojs? What would be different if I run Node.js without Mongoose/Mongojs? I can't find any good explanation of the big picture of how Mongoose or…
HaoQi Li
  • 11,970
  • 14
  • 58
  • 77
20
votes
1 answer

Inserting the current datetime in mongodb

I have been having trouble inserting an actual datetime object in mongodb using the mongojs driver for nodejs. Any help? var currentdate = new Date(); var datetime = currentdate.getDate() + "/" + (currentdate.getMonth()+1) + "/" +…
David
  • 679
  • 1
  • 9
  • 22
19
votes
2 answers

MongoDb : How to insert additional object into object collection?

I have a document "owner" that can have "n" number of camps and camps have "instructors" and instructors have "classes". Earlier I tried accomplishing this with nested arrays (see link to my post below), however I learned that the positional…
cpeele00
  • 883
  • 4
  • 14
  • 29
17
votes
5 answers

TypeError: Cannot read property '_id' of undefined

I am getting error "TypeError: Cannot read property '_id' of undefined" on a simple post request to save a document to the collection called books, My payload looks like this: { "name": "practical view", "author": "DN", "location": "room…
Chidu Murthy
  • 688
  • 3
  • 10
  • 26
15
votes
2 answers

Callback was already called async parallel

Hi I am trying to use the Async module to retrieve two users and do some processing after they have both been retrieved however I keep getting the error message: Callback was already called. Below is the code i currently…
sazap10
  • 263
  • 2
  • 7
  • 15
13
votes
1 answer

How to dynamically $set a subdocument field in mongodb?

I've run into a situation where I need to dynamically update the value of a field in a subdocument. The field may or may not already exist. If it doesn't exist, I'd like mongo to create it. Here's an example document that would be found in my Teams…
AJB
  • 7,389
  • 14
  • 57
  • 88
12
votes
2 answers

How do I iterate over an entire MongoDB collection using mongojs?

I'm using mongojs and I'm trying to iterate over all elements in a collection index = 0 db.keys.find({}, {uid: 1, _id: 0}).forEach((err, key) => if err? console.log err else console.log (++index) + " key: " + key_uid which…
Loourr
  • 4,995
  • 10
  • 44
  • 68
12
votes
2 answers

Send MongoDB query result as JSON using express

I'm writing an application where I use express, Node.js and MongoDB (using mongojs). I have a module db.js and a server.js, which have the snippets below. db.js var getUsersByCity = function(city, callback) { db.users.find({'city':…
Amaury Medeiros
  • 2,093
  • 4
  • 26
  • 42
7
votes
4 answers

MongoDB query for document older than 30 seconds

Does anyone have a good approach for a query against a collection for documents that are older than 30 seconds. I'm creating a cleanup worker that marks items as failed after they have been in a specific state for more than 30 seconds. Not that it…
Nick Parsons
  • 8,377
  • 13
  • 48
  • 70
6
votes
1 answer

how to insert a .json document to mongo server by mongojs in node

I'm new with nodeJS and MongoDB. I have this code: var fs = require('fs'); var mongojs = require('mongojs'); var db = mongojs('monitor', ["configurations"]); fs.readFile('json/object1.json', 'utf8', function (err, data) { if (err) throw err; …
Avigayil
  • 63
  • 1
  • 1
  • 3
6
votes
2 answers

How do I capture a MongoDB query as a string and display it in my Node JS page (using the mongojs driver)?

I would like to be able to query my mongoDB and display this result on my web page made with Node...right now I am using the mongojs driver - I've found the driver very very good for putting data into the DB - the syntax is the same as the Mongo…
PinkElephantsOnParade
  • 6,452
  • 12
  • 53
  • 91
5
votes
2 answers

Why is mongo dot notation replacing an entire subdocument?

I've got the following doc in my db: { "_id": ObjectId("ABCDEFG12345"), "options" : { "foo": "bar", "another": "something" }, "date" : { "created": 1234567890, "updated": 0 } } And I want to update options.foo and…
AJB
  • 7,389
  • 14
  • 57
  • 88
5
votes
1 answer

How to search for text or expression in multiple fields

db.movies.find({"original_title" : {$regex: input_data, $options:'i'}}, function (err, datares){ if (err || datares == false) { db.movies.find({"release_date" : {$regex: input_data + ".*", $options:'i'}}, function (err,…
summerNight
  • 1,446
  • 3
  • 25
  • 52
5
votes
3 answers

How to update the TTL on a collection?

Using NodeJS + MongoJS, I have connection to a mongo DB. I set a TTL on a collection with: myCollection.createIndex({createdAt: 1}, {expireAfterSeconds: 60 * 30}) Is it now possible to update the value for expireAfterSeconds ? If so, what's the…
Running Turtle
  • 12,360
  • 20
  • 55
  • 73
1
2 3
20 21