我是MongoDb的新手,我对插入数据有疑问。我用于用户'的Mongoose架构系列:
public interface UILInterfaceNative extends Library{
public PointerByReference Initialize(int hba, int port);
public int Scan(PointerByReference uil);
}
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
UILInterfaceNative uil = (UILInterfaceNative)Native.loadLibrary("UILInterfaceNative", UILInterfaceNative.class);
PointerByReference uilPointer = new PointerByReference();
uilPointer = uil.Initialize(0, 2);
int device = uil.Scan(uilPointer);
System.out.println("Device found: " + device);
}
}
我在第一次服务电话中将数据插入用户名,电子邮件和密码:
var user = new mongoose.Schema({
username : {type: String},
email : {type: String,index: {unique: true}},
password : {type: String},
feed : [{
title : {type: String},
description : {type: String},
latitude : {type:Number},
longitude : {type:Number},
feedImages : [{imageUrl: {type: String}}]
}]
});
然后我尝试将数据插入到上述id的Feed中。
app.post('/users',function(req,res) {
var username = req.body.username;
var email = req.body.email;
var password = req.body.password;
var userData = {'username':username,'email':email,'password':password};
new db.user(userData).save(function(err,result){
if (err) {
res.json({"success": '0', "message": "Error adding data"});
}
else {
res.json({"success": '1', "message": "Data added"});
}
});
});
未显示错误,但未插入数据。
答案 0 :(得分:1)
您的纬度和经度应转换为数字:
var latitude = Number(req.body.latitude);
var longitude = Number(req.body.longitude);