【发布时间】:2016-01-21 08:59:31
【问题描述】:
我正在尝试使用 nodeJS 将以下对象存储在谷歌数据存储中,但它返回 400“错误请求”错误
{
"_id":{
"$oid":"567e9e80067de880273095e0"
},
"name":"Windows 10",
"desc":"This is a Test",
"isSelfPaced":true,
"credit":[
{
"_id":"56640d4926b67c201b861cde",
"username":"Akash",
"displayName":"Gupta",
"email":"yesitsakash@gmail.com",
"role":"Author"
}
],
"video":{
"type":0,
"videoKey":"KHATEmotionalFulls_lowb84c0084-836c-008c-a850-328687e23d02.mp4",
},
"structure":4,
"category":"test2",
"subCategory":"dfdfdf",
"content":[
{
"id":"a053915c-8d10-4aa8-b464-c8a99154c3af",
"name":"Module 1",
"type":1,
"topics":[
"test1",
"test2"
],
"children":[
{
"id":"46f18a1a-6653-41cb-be5c-002200170bb9",
"name":"Unit 1",
"type":2,
"subtype":"1",
"video":{
"type":0,
"videoKey":"VID-20150920-WA0017ee56049d-2b08-aeb5-9b9c-b5188b1f7324.mp4",
},
"note":"<ul><li><b>This is a test<\/b><\/li><\/ul>",
"isSelfPaced":true
},
{
"id":"da4f53a3-7ea2-4fa8-9d48-4d7199a3450c",
"name":"quiz 1",
"type":2,
"subtype":3,
"questions":[
{
"question":"New Question",
"options":[
{
"text":"option 1",
"correct":true
}
]
}
],
"isSelfPaced":true
}
],
"time":3,
"isSelfPaced":true,
"desc":"This is a test"
}
],
"createdBy":{
"displayName":"Gupta",
"id":"56640d4926b67c201b861cde"
},
"createdAt":{
"$date":"2016-01-10T17:51:15.635Z"
},
"startDate":"1970-01-01T00:00:00.000Z",
"endDate":"1970-01-01T00:00:00.000Z",
"isPublish":true
};
datastore.insert('test2','test2',data,function(err,key){
if(err){
res.status(500).end();
}
else{
res.send(key);
}
});
});
NodeJS 代码:
var keyObject = dataset.key({
namespace: namespace,
path: [collectionName,utility.getGUID()]
});
dataset.save({key:keyObject,data:data,method:'insert'},function(err) {
if(err){
callback(err,null);
}
else{
callback(null,keyObject.path[1]);
}
});
更简单的场景正在运行,但如何使用 nodejs 将 jSON 数组存储在谷歌数据存储中
【问题讨论】:
-
我认为这个问题可以通过重新阅读您尝试使用的库的文档以及检查错误输出(您尚未提供)来解决
-
@Nick 在我的问题中也提到了它的 400“错误请求”错误。任何方式这都证明是无效的 JSON 问题,现在 git 已修复。非常感谢您的宝贵时间:)
标签: arrays json node.js google-compute-engine google-cloud-datastore