var mongoose = require('mongoose');
var db = mongoose.connection;
// db connect
db.on('error', console.error);
db.once('open', function() {
console.log('Conectado ao MongoDB.')
});
mongoose.connect('mongodb://localhost/rotiny');
// -- //
var msnSchemaUser = new mongoose.Schema({
name: String,
username: String,
password: String,
email: String,
roles: {
type: Array,
default: ['user']
}
});
var msnModuleUser = mongoose.model('User', msnSchemaUser);
var query = msnModuleUser.find();
query.exec('find', function(err, items) {
console.log(items)
});
Results that the code returns.
[ { roles: [ 'user' ],
__v: 0,
email: '[email protected]',
password: '12345',
username: 'rotiny',
name: 'Rotiny - BETA API',
_id: 5685e3f16d3e65ba3fa47e84 },
{ roles: [ 'user' ], __v: 0, _id: 5685e42f8deb044f405c6986 },
{ roles: [ 'user' ], __v: 0, _id: 5685e4e38deb044f405c6987 },
{ roles: [ 'user' ], __v: 0, _id: 5686068a8deb044f405c6988 },
{ roles: [ 'user' ], __v: 0, _id: 5686068a8deb044f405c6989 },
{ roles: [ 'user' ], __v: 0, _id: 5686068f8deb044f405c698a },
{ roles: [ 'user' ], __v: 0, _id: 568606908deb044f405c698b },
{ roles: [ 'user' ], __v: 0, _id: 5686069b8deb044f405c698c } ]
My question is the following.
Because I can not list those same data with this code in PHP
$m = new Mongo("mongodb://localhost"); // connect
$db = $m->selectDB("rotiny");
$collection = new MongoCollection($db, 'User');
$find = $collection->find();
foreach ($find as $doc) {
var_dump($doc);
}
The code just above in php, does not return anything.
Note: I have recently been using Mongo.
Can anyone tell me what I'm doing wrong?