将写好的lua脚本存进mongo,通过查询得到脚本,运行脚本出错,找不到local cjson = require('json')中的json

local script = {}
local cjson = require('json')
function script.payloadToRowData(payloadjson,topic)
local payloadlua=cjson.decode(payloadjson)
local ntopic=string.gsub(topic,'gw','/sys/0x16')
ntopic=string.gsub(ntopic,'zclresponse','thing/event/properties')
local json={}
local value=tonumber(payloadlua['commandData'], 16)
json['state1']=value
json['topic']=ntopic
return cjson.encode(json)
end
function script.rowDataToPayload(payloadjson,topic)
local payloadlua=cjson.decode(payloadjson)
local ntopic=string.gsub(topic,'/sys/0x16','gw')
ntopic=string.gsub(ntopic,'thing/event/properties','zclresponse')
local json={}
local value=tonumber(payloadlua['state1'],10)
json['commandData']=value
json['topic']=ntopic
return cjson.encode(json)
end
return script
:2: in main chunk
[Java]: in ?]

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
Python+OpenCV计算机视觉

Python+OpenCV计算机视觉

如何使用mongo-go-driver运行mongo命令?

<div class="post-text" itemprop="text"> <p>Hi there :) I'm working on a golang app linked to mongo DB (I use the official driver: <code>mongo-go</code>) and here's my problem,I want to execute this function </p> <pre><code>db.rmTickets.find().forEach(function(doc) { doc.created=new Date(doc.created) doc.updated=new Date(doc.updated) doc.deadline=new Date(doc.deadline) doc.dateEstimationDelivery=new Date(doc.dateEstimationDelivery) doc.dateTransmitDemand=new Date(doc.dateTransmitDemand) doc.dateTransmitQuotation=new Date(doc.dateTransmitQuotation) doc.dateValidationQuotation=new Date(doc.dateValidationQuotation) doc.dateDeliveryCS=new Date(doc.dateDeliveryCS) db.rmTickets.save(doc) }) </code></pre> <p>I see on godoc that a <code>Database.RunCommand()</code> exists but I'm not sure about how to use it. If someone can help :) Thanks </p> </div>

mongo-connector集成启动报错

mongo-connector启动命令: service mongo-connector start 然后报错: ![图片说明](https://img-ask.csdn.net/upload/201611/23/1479882609_290410.jpg) 在linux环境下面,好像是mongo-connector脚本命令43行有问题,请教高人如何解决!

golang mongodb将数据库库mongo迁移到mgo

<div class="post-text" itemprop="text"> <p>I want to change library for database from <code>github.com/mongodb/mongo-go-driver/mongo</code> to <code>github.com/globalsign/mgo</code>, my problem is I dont know how convert this code for new library :</p> <pre><code>import "github.com/mongodb/mongo-go-driver/mongo/options" res, err := s.totals().UpdateOne(ctx, bson.M{"contract_id": cID, "date": date}, bson.M{"$inc": bson.M{"value": value}}, options.Update().SetUpsert(true), ) </code></pre> <p>My current code :</p> <pre><code>collection := s.totals() err := collection.Update( bson.M{"contract_id": contractID, "date": date}, bson.M{"$inc": bson.M{"value": value}}, //options.Update().SetUpsert(true), ) </code></pre> <p>How i can convert this <code>options.Update().SetUpsert(true)</code> for use in new library ?</p> </div>

在 linux 的 sh 中执行 docker 命令不执行?

创建了一个自动任务,自动执行 sh 脚本,sh 内容如下: ``` #/bin/bash name=`date +%Y%m%d`_`date +%H%M%S` mkdir -p /home/mongo/cron/bak/$name docker exec -it mongo mongodump -h localhost -d dbname -o /home/mongo/cron/db -u username -p password ``` 文件在 /home/mongo/cron/run.sh **已经执行了** chmod u+x run.sh 为sh脚本文件添加执行权限 **现在问题是**:创建文件夹有效,说明脚本有执行,但最后一句,docker 命令没执行或者执行不成功 **想过问题原因**: 1: 权限问题,已经给了执行权限了 2:docker 命令错误,但是单独执行是没有问题的 原因到底在哪里呢,求大佬指点

从PHP调用MongoDB脚本

<div class="post-text" itemprop="text"> <p>I have mongodb script like below</p> <pre><code>function getSalaryByTitle(){ var db = connect('TestMongoDB'); var titles = db.titles.find({},{emp_no:1, title:1}); var titles_detail = titles.next(); var salaries = db.salaries.find({emp_no:{ $in: titles_detail } }); var jsonArr = []; while (salaries.hasNext()){ var salary_detail = salaries.next(); var title = titles.next(); jsonArr.push({ title: title['title'], salary: salary_detail['salary'] }); } return jsonArr; } </code></pre> <p>how can I call it from php? Can anyone help me with this?</p> <p>Thanks in advance..</p> </div>

在Mongo中减去日期

<div class="post-text" itemprop="text"> <p>I am trying to substract two dates in MonoDB using the aggreation framework.</p> <p>My code looks like this:</p> <pre><code>$ops = array( array('$project' =&gt; array("fieldMath" =&gt; array( '$subtract' =&gt; array( 'new ISODate()', 'new ISODate("last_interacted_date")' )), )), array('$match' =&gt; array('fieldMath' =&gt; array('$gte' =&gt; 2), ), ), ); $object -&gt; aggregate($ops); </code></pre> <p>The problem is I'm getting an error that I am trying to substract 2 string.</p> <blockquote> <p>Fatal error: Uncaught exception 'MongoResultException' with message 'localhost:27017: cant $subtract aString from a String</p> </blockquote> <p><code>new ISODate</code> and the <code>last_interacted_date</code> are both <code>ISODate</code> objects. </p> <p><strong>My goal</strong> is to subtract a 'last_did_something' date from the date today, and return results for all queries that are within 2 days.</p> <p>What am I doing wrong and how I can subtract dates?</p> </div>

nodejs使用connect-mongo出现问题

我用的版本是1.2.1是不是太老了? D:\somepackage\app\node_modules\connect-mongo\src\index.js:3 const Promise = require('bluebird'); ^^^^^ SyntaxError: Use of const in strict mode. at exports.runInThisContext (vm.js:73:16) at Module._compile (module.js:443:25) at Object.Module._extensions..js (module.js:478:10) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12) at Module.require (module.js:365:17) at require (module.js:384:17) at Object.<anonymous> (D:\somepackage\app\node_modules\connect-mongo\index.j s:1:80) at Module._compile (module.js:460:26) at Object.Module._extensions..js (module.js:478:10) 哪位前辈有经验指点下 谢谢

在使用Apache时,Php脚本停留在“new Mongo()”

<div class="post-text" itemprop="text"> <p>I wrote a little php login script. It searches in a mongoDb-collection for the provided credentials. If i run it from console with</p> <pre><code>php login.php </code></pre> <p>it runs flawless. However, if i try to log in from the html-interface it seems to be stuck at </p> <pre><code>$m = new Mongo(...); </code></pre> <p>directive, and doesn't continue with the other lines of code. I'm running over an apache server on my laptop, just to try what i'm doing.</p> </div>

MongoDB Compass有没有写mongodb命令行的地方?

作为一个可视化软件,有没有像navicat那样新建查询后写查询语句的地方? 就想下面这样的命令行语句在mongo.exe可以执行,那么能否再compass里的什么地方执行呢? db.grade_1_1.insert({"name": 'chen', "age": 7, "sex": 0});

Linux 启动mongodb服务,通过&设置为后台进程的问题

系统环境 centeros7 ;我通过普通用户启动一个mongodb服务,启动 shell 脚本如下: mongod --dbpath='/opt/mongodb/data/db/' & 服务启动后可以正常连接,但是我将terminal窗口关闭后重新打开一个新的,这时候却连不上了。 但是通过su切换到root用户,同样方式启动mongodb服务,然后关闭terminal窗口再次重新打开一个新的,(root 或是 普通用户)依然能能够连上。 请问这是为啥(普通用户 shell 的 huponexit 已经设置为 off)?

从Golang执行Bash脚本

<div class="post-text" itemprop="text"> <p>I am trying to figure out a way to execute a script (.sh) file from Golang. I have found a couple of easy ways to execute commands (e.g. os/exec), but what I am looking to do is to execute an entire sh file (the file sets variables etc.).</p> <p>Using the standard os/exec method for this does not seem to be straightforward: both trying to input "./script.sh" and loading the content of the script into a string do not work as arguments for the exec function. </p> <p>for example, this is an sh file that I want to execute from Go:</p> <pre><code>OIFS=$IFS; IFS=","; # fill in your details here dbname=testDB host=localhost:27017 collection=testCollection exportTo=../csv/ # get comma separated list of keys. do this by peeking into the first document in the collection and get his set of keys keys=`mongo "$host/$dbname" --eval "rs.slaveOk();var keys = []; for(var key in db.$collection.find().sort({_id: -1}).limit(1)[0]) { keys.push(key); }; keys;" --quiet`; # now use mongoexport with the set of keys to export the collection to csv mongoexport --host $host -d $dbname -c $collection --fields "$keys" --csv --out $exportTo$dbname.$collection.csv; IFS=$OIFS; </code></pre> <p>from the Go program:</p> <pre><code>out, err := exec.Command(mongoToCsvSH).Output() if err != nil { log.Fatal(err) } fmt.Printf("output is %s ", out) </code></pre> <p>where mongoToCsvSH can be either the path to the sh or the actual content - both do not work.</p> <p>Any ideas how to achieve this? </p> </div>

MongoDB $ ifNull条件与mgo

<div class="post-text" itemprop="text"> <p>I'm struggling porting a query from the mongo console to my Go code. I'm new to MongoDB so there might be additional mistakes I haven't taken into account.</p> <p>Sample data 'users' collection:</p> <pre><code>{ "_id" : ObjectId("592400188d84961b7f34b0cd"), "username" : "randomUser2", "location" : { "type" : "Point", "coordinates" : [ -17.282573, 63.755657 ] } } { "_id" : ObjectId("592400188d84961b7f34b0ce"), "username" : "randomUser1", "location" : { "type" : "Point", "coordinates" : [ -17.634135, 65.705665 ] } } </code></pre> <p>Sample data 'newscounter' collection:</p> <pre><code>{ "_id" : ObjectId("592400188d84961b7f34b0cd"), "count" : 14 } </code></pre> <p>The query in mongo looks like this:</p> <pre><code>db.users.aggregate([ { $geoNear: { near: { type: "Point", coordinates: [-21.861198,64.120877] }, distanceField: "distance", maxDistance: myDistance * 1000, spherical: true } }, { $sort: { "distance": 1 } }, { $lookup: { from: "newscounter", localField: "_id", foreignField: "_id", as: "news_count" } }, { $unwind: { path: "$news_count", preserveNullAndEmptyArrays: true } }, { $project : { "id": 1, "username": 1, "distance": 1, "news_count": { $ifNull : ["$news_count.count", 0] } } } ]) </code></pre> <p>The output is (I used random values for the calculated distance field here):</p> <pre><code>{ "_id" : ObjectId("592400188d84961b7f34b0cd"), "username" : "randomUser2", "distance" : 123, "news_count" : 14 } { "_id" : ObjectId("592400188d84961b7f34b0ce"), "username" : "randomUser1", "distance" : 456, "news_count" : 0 } </code></pre> <p>The part I've trouble with is the $ifNull in the $project stage.</p> <p>How do I build the $ifNull line in Go using the mgo package?</p> <p>I tried with:</p> <pre><code>"news_count": bson.M{ "$ifNull": [2]interface{}{"$news_count.count", 0}, } </code></pre> <p>but it returns always an empty string for the news_count field.</p> <p>Any help is greatly appreciated!</p> <p>EDIT [solved]:</p> <p>The issue was silly, I had the wrong <code>type</code> for the <code>news_count</code> field in the Go <code>struct</code>.</p> <p>For the sake of completeness the pipeline in Go is:</p> <pre><code>p := []bson.M{ bson.M{ "$geoNear": bson.M{ "near": bson.M{"type": "Point", "coordinates": center}, "distanceField": "distance", "maxDistance": maxDistance, "spherical": true, }, }, bson.M{ "$sort": bson.M{ "distance": 1, }, }, bson.M{ "$lookup": bson.M{ "from": "newscount", "localField": "_id", "foreignField": "_id", "as": "news_count", }, }, bson.M{ "$unwind": bson.M{ "path": "$news_count", "preserveNullAndEmptyArrays": true, }, }, bson.M{ "$project": bson.M{ "_id": 1, "username": 1, "distance": 1, "news_count": bson.M{ "$ifNull": []interface{}{"$news_count.count", 0.0}, }, }, }, } </code></pre> <p>The result <code>struct</code>:</p> <pre><code>type Result struct { ID bson.ObjectId `json:"id" bson:"_id"` Username string `json:"username" bson:"username"` Distance int64 `json:"distance" bson:"distance"` NewsCount int64 `json:"news_count" bson:"news_count"` } </code></pre> </div>

pymongo中如何判断是否查找到某条记录

# *-* coding: utf-8 *-* #!/usr/bin/python import pymongo import time conn = pymongo.Connection("127.0.0.1",27017) db = conn.test #连接库test num = db.posts.count({'text':'赵云'}) print num 我想查text字段为赵云的记录个数,这个命令 :db.posts.count({'text':'赵云'})在mongo的控制台中可以正确执行,但是在python脚本中却提示下面的错误: TypeError: count() takes exactly 1 argument (2 given) 还请诸位朋友帮忙看一下,十分感谢

java 调用Mongodb存储过程

Mongodb3.0以后 db.eval() Deprecated since version 3.0.若是mongodb要写存储过程(js脚本),是不是有什么替代的执行方法。同时mongodb -java-driver3.0中DB类也已经置为Deprecated,其方法eval(),doEval()也一样,而MongoDataBase类中我没有找到执行脚本的方法,请问各位大神是不是有什么替代的方法,还是Mongodb不再建议执行js脚本,但我项目有执行类似存储过程的需求,可有解决方案?

【求教】mongoDB插入速度怎么比MySQL还慢

MySQL版本:5.7.13 MongoDB版本:3.2 操作系统:Windows server 2008 R2 内存:8G python 2.7.11 本人MongoDB萌新一枚,用python分别写了一个循环插入的测试脚本,数据量为30万 MongoDB: ``` from pymongo import MongoClient import time def get_db(): #建立连接 client = MongoClient("localhost", 27017) #test,还有其他写法 db = client.test print "建立MongoDB数据库连接" return db def get_collection(db): #选择集合 collection = db['test'] print "连接数据库:test" return collection def insert(collection): i=0 f = open("phonenumbers.txt") f1=open("result_mongo.txt","w") # 返回一个文件对象 line = f.readline() # 调用文件的 readline()方法 #print line, start=time.clock() while line: user = {"name":"%s"%(line.strip('\n'))} collection.insert(user) line = f.readline() i=i+1 if i%30000==0: end = time.clock() print "%f: %f s" % (i,end - start) f1.write("%f条记录用时:%f s \n"%(i,end - start)) print "%f: %f s" % (i,end - start) print 'task over' f.close() f1.close() db=get_db() collection=get_collection(db) insert(collection) ``` MySQL: ``` #Mysql conn = MySQLdb.connect(host='localhost',port = 3306, user='root',passwd='root',db ='test',charset='utf8') cursor = conn.cursor() print 'connect Mysql success!' i=0 f = open("phonenumbers.txt") f1=open("result.txt","w") # 返回一个文件对象 line = f.readline() # 调用文件的 readline()方法 #print line, start=time.clock() while line: #print line.strip('\n') sql_content = """insert into t_phone(phone_number) values('%s')"""%(line.strip('\n')) #print sql_content cursor.execute(sql_content.decode('utf8').encode('gb18030')) # print(line, end = '')   # 在 Python 3中使用 i=i+1 if i%30000==0: end = time.clock() print "%f: %f s" % (i,end - start) f1.write("%f条记录用时:%f s \n"%(i,end - start)) line = f.readline() print 'task over' f.close() f1.close() conn.commit() cursor.close() conn.close() ``` 运行时间如下: ``` MySQL 30000.000000: 5.953894 s 60000.000000: 11.355339 s 90000.000000: 16.826594 s 120000.000000: 22.311345 s 150000.000000: 27.833271 s 180000.000000: 33.445231 s 210000.000000: 38.899494 s 240000.000000: 44.386738 s 270000.000000: 49.829280 s 300000.000000: 55.298867 s MongoDB 30000.000000: 17.713415 s 60000.000000: 35.223699 s 90000.000000: 52.518638 s 120000.000000: 69.901784 s 150000.000000: 87.370721 s 180000.000000: 105.004178 s 210000.000000: 122.643773 s 240000.000000: 140.226097 s 270000.000000: 157.490818 s 300000.000000: 175.007099 s 各位大神这是怎么回事? ```

mongodb如何将数组中的元素逐个转存到另一个集合(即图1到图2的转变)

![图1](https://img-ask.csdn.net/upload/201709/06/1504702109_821288.png) ![图2](https://img-ask.csdn.net/upload/201709/06/1504702132_67049.png)

在控制台上执行php脚本

<div class="post-text" itemprop="text"> <p>I have a php script, and I am trying to run it on my linux console. I can run it with curl and on any browser wtihout any errors. This is the error I am getting.</p> <pre><code>PHP Fatal error: Class 'Mongo' not found in ..... Fatal error: Class 'Mongo' not found in .... </code></pre> <p>I have no idea why I am getting this error, thank you</p> </div>

robomongo如何导入导出数据

mysql数据导入到mongol中该如何导入?如果带认证的mongol数据库如何导入数据,robomongo客户端有提供导入或者导出数据么?

循环删除MongoDB重复数据

导入数据时,不小心重复导入了,并且还勾选了"Insert with new _id" 现在数据库中有几千组这样重复的数据,怎么样才能删除呢 只有_id是不一样的,其他都一样 ``` { "_id" : ObjectId("58c0e5c13c4a1aae0828d7a9"), "date_time" : "2017-03-09 13:18:28", "object_code" : "D1_6wgglB", "status" : 0, "value" : 25.235034942626953 } { "_id" : ObjectId("58f9b18bfa94a03098123da7"), "date_time" : "2017-03-09 13:18:28", "object_code" : "D1_6wgglB", "status" : 0, "value" : 25.235034942626953 } ```

Mongodb用PHP脚本保存印地文文本

<div class="post-text" itemprop="text"> <p>I am looking the solution to save "Hindi" font in Mongo DB but nothing found.I have tried to below code but this is also not working</p> <pre><code>$title = mb_convert_encoding($title, "UTF-8", "ISO-8859-1"); </code></pre> <p>I have also followed below link but its not working</p> <p><a href="https://stackoverflow.com/questions/21085939/how-to-store-different-languagenon-english-data-in-mongodb-field-and-retrive-t">How to Store different language(non english) data in MongoDB Field and retrive the same data?</a></p> <p>Please help me if anyone have idea.I have spent more than 3 to 4 hours but not working.</p> </div>

2019 Python开发者日-培训

2019 Python开发者日-培训

150讲轻松搞定Python网络爬虫

150讲轻松搞定Python网络爬虫

设计模式(JAVA语言实现)--20种设计模式附带源码

设计模式(JAVA语言实现)--20种设计模式附带源码

YOLOv3目标检测实战:训练自己的数据集

YOLOv3目标检测实战:训练自己的数据集

java后台+微信小程序 实现完整的点餐系统

java后台+微信小程序 实现完整的点餐系统

三个项目玩转深度学习(附1G源码)

三个项目玩转深度学习(附1G源码)

初级玩转Linux+Ubuntu(嵌入式开发基础课程)

初级玩转Linux+Ubuntu(嵌入式开发基础课程)

2019 AI开发者大会

2019 AI开发者大会

玩转Linux:常用命令实例指南

玩转Linux:常用命令实例指南

一学即懂的计算机视觉(第一季)

一学即懂的计算机视觉(第一季)

4小时玩转微信小程序——基础入门与微信支付实战

4小时玩转微信小程序——基础入门与微信支付实战

Git 实用技巧

Git 实用技巧

Python数据清洗实战入门

Python数据清洗实战入门

使用TensorFlow+keras快速构建图像分类模型

使用TensorFlow+keras快速构建图像分类模型

实用主义学Python(小白也容易上手的Python实用案例)

实用主义学Python(小白也容易上手的Python实用案例)

程序员的算法通关课:知己知彼(第一季)

程序员的算法通关课:知己知彼(第一季)

MySQL数据库从入门到实战应用

MySQL数据库从入门到实战应用

机器学习初学者必会的案例精讲

机器学习初学者必会的案例精讲

手把手实现Java图书管理系统(附源码)

手把手实现Java图书管理系统(附源码)

极简JAVA学习营第四期(报名以后加助教微信:eduxy-1)

极简JAVA学习营第四期(报名以后加助教微信:eduxy-1)

.net core快速开发框架

.net core快速开发框架

玩转Python-Python3基础入门

玩转Python-Python3基础入门

Python数据挖掘简易入门

Python数据挖掘简易入门

微信公众平台开发入门

微信公众平台开发入门

程序员的兼职技能课

程序员的兼职技能课

Windows版YOLOv4目标检测实战:训练自己的数据集

Windows版YOLOv4目标检测实战:训练自己的数据集

HoloLens2开发入门教程

HoloLens2开发入门教程

微信小程序开发实战

微信小程序开发实战

Java8零基础入门视频教程

Java8零基础入门视频教程

相关热词 c#跨线程停止timer c#批量写入sql数据库 c# 自动安装浏览器 c#语言基础考试题 c# 偏移量打印是什么 c# 绘制曲线图 c#框体中的退出函数 c# 按钮透明背景 c# idl 混编出错 c#在位置0处没有任何行
立即提问