一个人如何在Mongodb中添加文本文件? [英] How can one add text files in Mongodb?

查看:80
本文介绍了一个人如何在Mongodb中添加文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一定的要求在mongodb中插入一个文本文件,将其取回,然后检查文件是否相同.我希望在没有GridFS的情况下执行此操作,因为我要使用的文件小于16MB,所以考虑到mongodb的设置是非常基本的,因此你们可以建议我执行此操作的方法.

I have certain requirement to insert a text file in mongodb, retrieve it back and then check that whether files are same. I am hoping to do it without GridFS as the files i want to use is lesser than 16MB, so can you guys plz suggest me ways to do it, considering that set up of mongodb is very basic one.

谢谢

推荐答案

小于16 MB的文本文件可以作为简单的键值对存储在普通文档中.不需要GridFS,也不需要Binary或JSON对象.如有疑问,请尝试.有用.将文件的内容读取到变量中,然后将其存储在键(例如我不知道的数据")中.检索对象并将'data'键的值写入您喜欢的任何内容.换行符均被保留,因此无需在文件中执行任何操作.真的很简单.

A text file that is less than 16 MB can be stored as a simple key-value pair in a plain document. No need for GridFS and no need for Binary or JSON objects. If in doubt, try it. It works. Read the contents of the file into a variable and store it against a key such as, I don't know, 'data'. Retrieve the object and write the value of the 'data' key to whatever you like. Line breaks are all preserved so no need to do anything within the file. Really simple.

这篇关于一个人如何在Mongodb中添加文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆