我正在尝试从我的mongodb数据库中获取信息,但它不断返回一个空对象。我从一个名为" users"的集合中获取信息时使用的完全相同。它有效,但没有其他任何东西。
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var url = 'mongodb://test:test@124.355.99.268:27017/admin';
mongoose.connect(url);
var userPBData = new Schema ({
_id: mongoose.Schema.Types.ObjectId,
email: String,
password: String,
token: String,
name: String,
phone: String
});
var UserPB = mongoose.model('user_pb', userPBData);
UserPB.find( function(err, rows){
if(err) {
console.log(err);
}else{
console.log(rows);
}
})
" user_pb:
中的数据库文档 {
"_id":"5ab6815820568524b570f818",
"email":"test@test.se",
"password":"dac2cc2b9bfc297f2ecebe3bc98a0d248",
"token":"6c4c10d6e2c1067faa3ff8aad0d8542b3a5e55f805bab397b18ca16b8f986a0c4",
"name":"Test",
"phone":"har ej"
}
控制台输出:
[]
我做错了什么?
非常感谢您的帮助!
答案 0 :(得分:0)
var data = [
{age : 10 , score : 2000},
{age: 50 , score : 500},
{age: 20 , score : 500},
{age: 45 , score : 100},
{age: 32 , score : 1000},
{age: 89 , score : 552},
];
var margin = {top : 40 , right:40, bottom:40, left:40},
width = 600 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append('g')
.attr("transform",
"translate(" + margin.left + "," + margin.top + ")")
var x = d3.scaleLinear()
.domain(d3.extent(data, function(d) { return d.age; }))
.range([0, width ])
var y = d3.scaleLinear()
.domain([0, d3.max(data, function(d) { return d.score; })])
.range([height, 0 ])
var xAxis = d3.axisBottom()
.scale(x);
var yAxis = d3.axisLeft()
.scale(y);
svg.append("g")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
svg.append('g')
.call(yAxis);
svg.selectAll(".dot")
.data(data)
.enter().append('circle')
.attr("cx", function(d){return d.age})
.attr("cy", function(d){return d.score})
.attr("fill", "blue")
.attr("r",3)
查询的第一个参数应该是一个选择器。然后你应该回电话。
UserPB.find( function(err, rows){
if(err) {
console.log(err);
}else{
console.log(rows);
}
})