Node.js用于解析cloudant中的文件的代码

时间:2021-12-17 18:59:28

I loaded a log file ( text format) in the Cloudant. I am not sure if any node.js code is available to parse files or do I need to write my own parser ?

我在Cloudant中加载了一个日志文件(文本格式)。我不确定是否有任何node.js代码可用于解析文件或我是否需要编写自己的解析器?

3 个解决方案

#1


2  

This is a good tutorial on how to access your documents in Cloudant from a node.js application in Bluemix.

这是一个很好的教程,介绍如何从Bluemix中的node.js应用程序访问Cloudant中的文档。

https://www.ibm.com/developerworks/community/blogs/theTechTrek/entry/a_cloud_medley_with_ibm_bluemix_cloudant_db_and_node_js?lang=en

https://www.ibm.com/developerworks/community/blogs/theTechTrek/entry/a_cloud_medley_with_ibm_bluemix_cloudant_db_and_node_js?lang=en

require('http').createServer(function(req, res) {
//Set up the DB connection
if (process.env.VCAP_SERVICES) {
// Running on Bluemix. Parse for  the port and host that we've been assigned.
var env = JSON.parse(process.env.VCAP_SERVICES);
var host = process.env.VCAP_APP_HOST;
var port = process.env.VCAP_APP_PORT;
....
}
....
// Perform CRUD operations through REST APIs
// Insert document
if(req.method == 'POST') {
insert_records(req,res);
}
// List documents
else if(req.method == 'GET') {
list_records(req,res);
}
// Update a document
else if(req.method == 'PUT') {
update_records(req,res);
}
// Delete a document
else if(req.method == 'DELETE') {
delete_record(req,res);
}
}).listen(port, host);

#2


1  

If you are inserting a JSON document into the Cloudant DB, then you shouldn't have to do any special parsing when you get it out of the DB.

如果要将JSON文档插入Cloudant DB,那么当您将其从DB中取出时,不必进行任何特殊的解析。

Are you also wondering how to retrieve it? Without knowing more about what library you're using or how you want to retrieve the document (whether by doc_id, by querying using an index, etc.), it's hard to offer much guidance. But, if you have the document's id and you're using the Cloudant Node.js Client, then you can use the db.get function.

你还想知道如何检索它吗?如果不了解您正在使用的库或想要检索文档的方式(无论是通过doc_id,通过使用索引查询等),也很难提供很多指导。但是,如果您拥有文档的ID并且您正在使用Cloudant Node.js客户端,那么您可以使用db.get函数。

#3


0  

I think I need a little more information to help. So, a couple questions for you:

我想我需要更多的信息来帮助。所以,有几个问题要问你:

  • What format is the log's text in? For example, JSON? XML? Something else?
  • 日志文本的格式是什么?例如,JSON? XML?别的什么?
  • How did you add the text to Cloudant to start with? Are you using any particular module to interact with Cloudant? (For example, I use the Cloudant Node.js Client.)
  • 你是如何将文本添加到Cloudant的?您是否使用任何特定模块与Cloudant进行交互? (例如,我使用Cloudant Node.js客户端。)

#1


2  

This is a good tutorial on how to access your documents in Cloudant from a node.js application in Bluemix.

这是一个很好的教程,介绍如何从Bluemix中的node.js应用程序访问Cloudant中的文档。

https://www.ibm.com/developerworks/community/blogs/theTechTrek/entry/a_cloud_medley_with_ibm_bluemix_cloudant_db_and_node_js?lang=en

https://www.ibm.com/developerworks/community/blogs/theTechTrek/entry/a_cloud_medley_with_ibm_bluemix_cloudant_db_and_node_js?lang=en

require('http').createServer(function(req, res) {
//Set up the DB connection
if (process.env.VCAP_SERVICES) {
// Running on Bluemix. Parse for  the port and host that we've been assigned.
var env = JSON.parse(process.env.VCAP_SERVICES);
var host = process.env.VCAP_APP_HOST;
var port = process.env.VCAP_APP_PORT;
....
}
....
// Perform CRUD operations through REST APIs
// Insert document
if(req.method == 'POST') {
insert_records(req,res);
}
// List documents
else if(req.method == 'GET') {
list_records(req,res);
}
// Update a document
else if(req.method == 'PUT') {
update_records(req,res);
}
// Delete a document
else if(req.method == 'DELETE') {
delete_record(req,res);
}
}).listen(port, host);

#2


1  

If you are inserting a JSON document into the Cloudant DB, then you shouldn't have to do any special parsing when you get it out of the DB.

如果要将JSON文档插入Cloudant DB,那么当您将其从DB中取出时,不必进行任何特殊的解析。

Are you also wondering how to retrieve it? Without knowing more about what library you're using or how you want to retrieve the document (whether by doc_id, by querying using an index, etc.), it's hard to offer much guidance. But, if you have the document's id and you're using the Cloudant Node.js Client, then you can use the db.get function.

你还想知道如何检索它吗?如果不了解您正在使用的库或想要检索文档的方式(无论是通过doc_id,通过使用索引查询等),也很难提供很多指导。但是,如果您拥有文档的ID并且您正在使用Cloudant Node.js客户端,那么您可以使用db.get函数。

#3


0  

I think I need a little more information to help. So, a couple questions for you:

我想我需要更多的信息来帮助。所以,有几个问题要问你:

  • What format is the log's text in? For example, JSON? XML? Something else?
  • 日志文本的格式是什么?例如,JSON? XML?别的什么?
  • How did you add the text to Cloudant to start with? Are you using any particular module to interact with Cloudant? (For example, I use the Cloudant Node.js Client.)
  • 你是如何将文本添加到Cloudant的?您是否使用任何特定模块与Cloudant进行交互? (例如,我使用Cloudant Node.js客户端。)