Tuesday 15 May 2012

node.js - mongodb collection inserting record is not working -



node.js - mongodb collection inserting record is not working -

while inserting collection in mongo db working nodejs , mongoose, defined 2 files

the model.js

var mongoose = require('mongoose'); mongoose.connect('mongodb://localhost/stack1'); var stackschema = mongoose.schema({ name: string }) var schema = mongoose.schema, objectid = schema.objectid; var tagdata = new schema( { tag : string, info :[viewdata] } ) var viewdata = new schema({ view : string, date : date }); module.exports = mongoose.model('tag', tagdata);

the view.js

var tag = require('./model'); var view =({ "view" : "700", "date" : "2001/1/20" }); var tag = new tag( {"tag" : "java"} ); tag.data.push(view); //console.log(tag) tag.save(function (err) { if (!err) console.log('success!'); });

while executing above code can see sucess message in console

bash $ node view.js success!

when query mongodb collections homecoming nothing

> db.stack1.find()

what wrong i'm doing , how can right it

that find query looking in stack1 collection of default database in shell.

to query contents of tags collection in stack1 database you're targeting code:

> utilize stack1 > db.tags.find()

node.js mongodb mongoose

No comments:

Post a Comment