I want to use sequalize but not with sqlite , postgres etc. . I want to put my data in JSON file is it possible ? Or is there any library like sequelize which i can use json file as a database ?
Yes! There are quite a few npm packages available which suits your requirement.
Here are few for your reference,
node-json-db - A simple "database" that use JSON file for Node.js project. - https://www.npmjs.com/package/node-json-db
disk-db - A Lightweight Disk based JSON Database with a MongoDB like API - https://www.npmjs.com/package/diskdb
low-db - JSON database for Node and the browser powered by lodash API - https://www.npmjs.com/package/lowdb
Hope this helps!
Related
I am working on a backend application with node using typescript / javascript. My backend is using a sqlite database. I structured my project so that there is one file that contains all the database logic.
I could either write a module that will be required by all modules that or I could write a class which connects to the database in the constructor.
For me it seems a little bit weird to pack all database logic in a module that is not an object. What is the best practice in this case and why? (I know this might be a stupid question but I'm just a hobbyist)
Thanks in advance
In my case I make the connection to the database before running the server. In pseudocode:
connectorDB.connect( path, config, () => {
server.listen( port )
})
It will depend on how important the database connection is in the operation of your app.
I am new to elasticsearch and I am trying to build a movie search app. For this I plan to get data from kaggle and add to my elasticsearch which I have setup locally at localhost:9200. I see this in the localhost link:
name "bxiIZLL"
cluster_name "elasticsearch"
cluster_uuid "zc_JPmw4TQ2G5bvahEF6LQ"
version
number "5.6.14"
build_hash "f310fe9"
build_date "2018-12-05T21:20:16.416Z"
build_snapshot false
lucene_version "6.6.1"
tagline "You Know, for Search"enter code here
Now I need to add Kaggle data to this server. How can I do it?
I saw somewhere the curld -XPUT command. I am not sure how that can work with Kaggle.
A follow up question - if I want to publish my app later on, how can I host the elasticsearch ?
In order to upload a CSV file to elasticsearch:
download the file.
use logstash in order to read the file using file input
modify and transform the data as you need using logstash's CSV filter
output logstash to elasticsearch
For your follow up question - how can I host Elasticsearch - you can either run it by your own, in AWS EC2 for example, or use a managed service like Elastic cloud or AWS ES. good luck
I only need to use Parse sever cloud functions, How can I run parse server without mongodB
How to use Parse server without MongoDb ?
You cannot run a Parse Server instance without a database. For example, Parse store login session into the database
Two databases available with Parse Server
According to the documentation you have two choices of databases:
Postgres
MongoDb
So if you do not want to use MongoDb you have to use Postgres
Here is the difference between theses two databases
How to switch databases ?
If you want to change your database from a MongoDb to a Postgres, you just have to change the configuration:
var api = new ParseServer({
databaseURI: 'postgres://my.awesome.postgres.uri',
});
Hope my answer help you 😊
I am trying to insert the record into my mongoDB. Here is what I tried:
$.ajax({
type: "POST",
url: "http://localhost:28017/messages_sent/better/?doc=",
data: {
thread_id: event.threadID,
message_id: event.messageID,
user_email: sdk.User.getEmailAddress(),
token: token
},
dataType: "JSON"
});
countUsage();
chrome.storage.sync.set({ "last_tracked_email_date": Date.now() });
alert("hello");
}
});
I am trying to look into the MongoDB, but could not find any thing in the database.
How I can insert the record into MongoDB using javascript and Rest API of MongoDB itself?
After a good discussion, I get to know that you were trying, is to just insert data in Mongo.
And this Mongo's rest API feature only supports retrieving data
from official docs
The mongod process includes a simple REST API as a convenience. With no support for insert, update, or remove operations, it is generally used for monitoring, alert scripts, and administrative tasks.
So, there are many ways you can insert data in Mongo:
Using APIs in server side code using any server side lang like Python/java/node
Using mongo shell, simple insert
using some GUI tool, like robomongo
and I'm sure there are more
But in comments, OP wanted some data in Mongo to test functionality, so writing APIs for just inserting is not a great solution.
So, if you just want to insert data and comfortable using CLI, then just go in mongo shell, and insert directly into the collection.
But if not, then Robomongo is very efficient. It's made for adding/removing and other CRUD operations.
Simple steps for using robomongo:
Download from official site and install
Open it and click on connect, add your port (default 28017) and host (localhost)
Now on lhs, click on MongoDB and you should see you dbs in it it, if you've created those.
Then you can see your collections inside it, and just right click and click on insert option and you can add your JSON into it and click save.
That's it, doc is saved in collection. Simple right.
For a project, we're going to use the MEAN stack. Having Angularjs as the frontend framework, is there a possibility for the framework directly accessing the data from mongodb (Bypassing node and express)?
Also, is it possible to use meteorjs on the client side? If ever, what are key advantages and can it do direct access to mongodb as well?
Frontend accesing MongoDB is possible, via its HTTP (rest) interface
http://docs.mongodb.org/ecosystem/tools/http-interfaces/
To get the contents of a collection (note the trailing slash):
http://127.0.0.1:28017/databaseName/collectionName/
To add a limit:
http://127.0.0.1:28017/databaseName/collectionName/?limit=-10
To skip:
http://127.0.0.1:28017/databaseName/collectionName/?skip=5
To query for {a : 1}:
http://127.0.0.1:28017/databaseName/collectionName/?filter_a=1
Separate conditions with an &:
http://127.0.0.1:28017/databaseName/collectionName/?filter_a=1&limit=-10
Same as db.$cmd.findOne({listDatabase:1}) on the admin database in the shell:
http://localhost:28017/admin/$cmd/?filter_listDatabases=1&limit=1
To count documents in a collection:
http://host:port/db/$cmd/?filter_count=collection&limit=1
However, I personally discourage this approach. Node/Express can be a simple wrapper for auth/auth before you make any changes to DB.