Tag: string

Mongoose。查找string参数

我有一个函数使用mongoose来查询我的数据库。 连接已经起作用。 但是,如果我不使用实际的string,而是stringvariables,那么.find返回一个未定义的对象(即没有find任何东西)。 这里是代码: function getUser(obj, callback){ console.log("obj.key: " + obj.key[0].toString() + ":" + obj.value[0].toString()); var first = "name.first"; console.log("first: " + first); var second = "nicholas"; console.log("second: " + second); User.findOne({first:second}, 'name telephone address1 address2 city state zip country', function(err, user){//nothing can be found when not directly using a string!!! console.log("got this user: " […]

玉中的variables中的长string

我正在编写一个支持多种语言的Web应用程序。 我正在做的是将string传递给翻译类,它将执行翻译。 现在,我需要在我的模板中添加一些长文本,我想在多行上提供可读性。 – var longText = 'Some really long text … '; // … p #{i18n.tr(longText)} 我想做类似的事情 – var longText = 'Some text ' + – 'some other text' // … p #{i18n.tr(longText)} 不幸的是,玉不喜欢那样。 是否有可能在玉的多行string?

Meteor的Iron Router:在客户端和服务器端获得查询参数

那里 在我的应用程序中,如果有人在URL上传递参数,我想在模板上做不同的事情。 我知道我可以在服务器端使用this.params.query查询string,但我怎么可以传递给客户端或在客户端获取此值? 在我的情况下,我会发送一个可选的redirect的URL,如果它通过,主任务后,我的应用程序将redirect到给定的url的用户。 但是我只知道如何在服务器端看到redirect ,而不是在客户端,所以当我提交表单时,这些信息就会丢失 你可以帮帮我吗?

如何在Node.js中检查string是明文还是base64格式

我想检查给我的函数给定的string是纯文本还是base64格式。 我能够将纯文本编码为base64格式并将其反转。 但我想不出任何方式来validationstring是否已经是base64格式。 任何人都可以请build议在节点js这样做的正确方法? 是否有任何API可以在节点js中使用。

符号原型的string表示?

而我意识到Symbol的不能自动/无声地转换为string(请参阅这里的 “符号types转换”): s = Symbol('s'); typeof s; // -> 'symbol' s; // -> 'Symbol (s)' s.toString(); // -> 'Symbol (s)' using Symbol.prototype.toString() String(s); // -> 'Symbol (s)' using safe String(s) conversion s +''; // throws 'TypeError: Cannot convert a Symbol value to a string' as expected 我很惊讶/困惑,试图获取一个符号的原型的string表示会引发exception,无论是使用自动string转换,显式调用.toString或使用“安全”string(sym)转换 : s = Symbol('s'); typeof s; // -> […]

正则expression式匹配string中的开始([)和结束(,)(仅)

这是我的string: [{ "name": "Neuromancer","genre": "cyberpunk" }, 我想用replace方法删除[in the beginning和come(,)。 我这样做是因为我无法弄清楚如何正确编写正则expression式: line = line.replace(/\[/,""); line = line.replace(/\,$/,""); 谢谢 :)

JSON.parse给string中的换行符赋予exception

我收到以下string: var str='{"message":"hello\nworld"}'; 我需要把它变成JSON对象。 但是,由于\n ,我尝试使用JSON.parse(str)时出现exception 我看到这个问题,但没有帮助。 从那以后,我试着var j=JSON.parse(JSON.stringify(str)) 但是当我使用typeof j时,我仍然得到string而不是对象 我知道使用\\n作品,但事情是,它不打印在新行当我需要使用的价值。 更新:好的,我只是意识到\\n正在工作。 我正在使用它将\n转换为\\n : var str='{"message":"hello\nworld"}'; str=str.replace(/\n/g, "\\\\n").replace(/\r/g, "\\\\r").replace(/\t/g, "\\\\t"); var json=JSON.parse(str); console.log(json.message); 有人可以纠正它吗?

node.js将包含空格和嵌套string的string转换为json

我正在处理一个将AWS ELB日志推送到ElasticSearch的Lambda函数。 我从S3读取ELB日志,每个文件包含大约500行,如下所示: 2016-08-10T01:03:42.216242Z foaas 66.249.79.176:61945 172.31.45.185:80 0.000044 0.194952 0.000039 200 200 0 30 "GET http://www.foaas.com:80/you/JSON/kelly HTTP/1.1" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" – – 由于该string包含空格,分号,嵌套的string,加号等。我真的在最好的方式来将每一行转换为JSON的损失。 我尝试过使用split(),但是在给出string中所有不寻常的字符的情况下,不能让它玩得很好。 我的计划是使用AWS在这里logging的字段设置key:value对。 任何build议将是最受欢迎的。 谢谢。

zerorpc:如何将string数据从python转换为节点

我需要从nodejs中调用一个python脚本并获取结果。 我发现了似乎很适合的zerorpc库。 python脚本返回一个string数组,但在节点中我得到了二进制数据的对象。 这是pythonzerorpc服务器: # python zerorpc server import zerorpc class HelloRPC(object): def test(self): return ["A", "B", "C"] server = zerorpc.Server(HelloRPC()) serrver.bind("tcp://0.0.0.0:4242") server.run() 这是节点zerorpc客户端: // nodejs zerorpc client var zerorpc = require("zerorpc") var client = new zerorpc.Client(); client.connect("tcp://127.0.0.1:4242"); client.invoke("test", function(error, response, more) { if (response) { for (var i = 0; i < response.length; i++) […]

使用NodeJS为MongoDB添加值

目前我有需要插入到mongodb的数据。 数据已经成功插入到mongodb中,但是我想添加一些数据并将其附加到mongodb中。 我怎么能这样做? 这是我的代码inserting data到mongodb var MongoClient = require('mongodb').MongoClient , format = require('util').format; MongoClient.connect('mongodb://127.0.0.1:27017/test', function(err, db) { if(err) throw err; var collection = db.collection('test_insert'); collection.insert({ values:parsestring() }, function(err, docs) { collection.count(function(err, count) { console.log(format("count = %s", count)); }); }); // Locate all the entries using find collection.find().toArray(function(err, results) { console.dir(results); // Let's close the db […]