for first block of code , console.log("ff : "+ff) prints exactly like this :
ff : { _id : sd845y3hishofiuwhei , fullname : 'sachin' }
console.log("ff JSON : "+JSON.stringify(ff)); // this line prints like below :
ff JSON : [{"_id":"sd845y3hishofiuwhei" , "fullname" : "sachin" }]
how can i get that "sachin" separately in a separate variable ?
var fullname=SampleModel.find({uname:req.session.uname},{fullname : true},function(err,ff){
if(!err){
console.log("ff : "+ff);
console.log("ff JSON : "+JSON.stringify(ff));
return ff;
}else {
return null;
}
});
the below block of code is giving error like "invalid object id " . what can be the problem ?
var ret= AnotherModel.find({_id : { $nin : ["1","2"] } }, function(err,details){
if(!err) {
res.send(details);
}
else {
console.log("Error : "+err);
res.send(err);
}
});
i am implementing textarea like this
<textarea id="myarea" cols="100" rows="20" ></textarea>
output box is changing its height when i change rows , but that cols , when i change "cols" , its width not changing . the output box also has small width , i check in both chrome and mozilla. Whats the solution ? Thanks
I understand that you use mongoose and not only mongodb driver.
In the first block of code, the ff value isn't a string but an array of objects.
You can access "sachin" variable just doing something like : var fullname = ff[0].fullname;
Of course, it's best to iterate through the array but you get the idea.
If you want only one object to be retrieved, you should use "findOne" function instead and then you would be able to access "sachin" like this : var fullname = ff.fullname;
For the second question, you should use Query system. Queries are delayed requests that you can chain and tune more finely. To delay your query, just ommit the callback function : var query = Model.find({});
Then, add the filter you want, in your case : query.where('_id').nin(['1', '2']);
Finally, execute it :
query.exec(function (err, docs) {
// called when the `query.complete` or `query.error` are called
// internally
});
Informations about finding docs and about queries.