我有一个名为" user"我想在其中插入带有字符串键和整数值的映射。我正在使用node.js的cassandra-driver。
这是代码:
var cassandra = require('cassandra-driver');
var config = require('./config.js');
var cassandraClient = new cassandra.Client({contactPoints: config.cassandra.hosts, keyspace: config.cassandra.keyspace});
var jsonObj = {"id":979,"cardId":17423,"categoryType":"C","user":"Çakal Karlos","email":"demo@email.com","phone":"+902124572020","companyId":4560,"companyCount":11,"userName":"userT6162pgc","password":"wq6162erwrr6162fd12","licenseList":[{"id":100,"code":"HD","count":1}]};
var map= {};
for(var i = 0; i < jsonObj.licenseList.length; i++){
map[i] = {jsonObj.licenseList[i].code.concat(':').concat(jsonObj.licenseList[i].id).toString) : jsonObj.licenseList[i].count];
}
console.log(map[0]);
var params = [jsonObj.userName,jsonObj.cardId, jsonObj.categoryType, jsonObj.companyCount, jsonObj.companyId, jsonObj.email, jsonObj.id, map[0], jsonObj.password, jsonObj.phone, jsonObj.user];
cassandraClient.execute(config.query, params, {prepare: true}, function(err) {
if(err){
console.log(err);
}
console.log('Row updated on the cluster');
});
当我查询表时,结果是,
username | cardid | categorytype | companycount | companyid | email | id | licenselist | password | phone | user
--------------+--------+--------------+--------------+-----------+----------------+-----+-------------+---------------------+---------------+-----------------
userT6162pgc | 17423 | C | 11 | 4560 | demo@email.com | 979 | null | wq6162erwrr6162fd12 | +902124572020 | \xc7akal Karlos
我无法插入地图,我无法创建地图。有可能吗?
答案 0 :(得分:-1)
我找到了答案
var cassandra = require('cassandra-driver');
var config = require('./config.js');
var cassandraClient = new cassandra.Client({contactPoints: config.cassandra.hosts, keyspace: config.cassandra.keyspace});
var jsonObj = {"id":979,"cardId":17423,"categoryType":"C","user":"Çakal Karlos","email":"demo@email.com","phone":"+902124572020","companyId":4560,"companyCount":11,"userName":"userT6162pgc","password":"wq6162erwrr6162fd12","licenseList":[{"id":100,"code":"HD","count":1}]};
var map= {};
for(var i = 0; i < jsonObj.licenseList.length; i++){
map[jsonObj.licenseList[i].code+':'+jsonObj.licenseList[i].id] = jsonObj.licenseList[i].count;
}
console.log(map);
var params = [jsonObj.userName,jsonObj.cardId, jsonObj.categoryType, jsonObj.companyCount, jsonObj.companyId, jsonObj.email, jsonObj.id, map, jsonObj.password, jsonObj.phone, jsonObj.user];
cassandraClient.execute(config.query, params, {prepare: true}, function(err) {
if(err){
console.log(err);
}
console.log('Row updated on the cluster');
});