Alternative for mongodb $push function in postgres - mongodb

Converting the MongoDb queries into postgresql.
In mongoDb we the basic usage of $push is as follows :
https://docs.mongodb.org/v3.0/reference/operator/aggregation/push/
Is there any alternative for this in postgresql or we need to implement it using the code.

You can do this using array_agg function in Postgres.
See Sample code(shamelessly copied ) : http://www.sqlfiddle.com/#!15/21b2b/1

Related

How we convert group_concat function of sql in mongoose?

group_concat of sql in mongoose?
[Sequelize.fn('group_concat', Sequelize.col('id')), 'products']
Query written in sql using sequelize. I am expecting to convert it in to mongoose.
Use aggregation frameworks of mongodb
Conversion of above code is
id is equal to _id in mongodb
Insert below line of code in aggregation object.
{$group:{id:"_id",products:{Spush:"$_id"}}

Bulk insert in Mongodb and Postgresql

I am doing a comparison on Postgresql vs Mongodb on insert.I am using the copy command (from file to table) in Postgresql and i am wondering what is the equivalent command in mongodb.I think that the answer is the insert_many(dict)But i want be sure.Any advice would be appreciated.Thanks in advance!
If you want to insert multiple documents in mongodb, you can use
db.collectionName.insertMany([{title: 'doc 1'},{title: 'doc2'},......]}

MongoDb db.collection.find() With Special Character

I am trying to write a simple query in MongoDb using PyMongo driver as such
mongo.db.people.find_one({'name': 'Tést Name'})
mongo.db.people.find_one({'name': 'Test_O%27Name'})
Both of these queries are returning null. I have checked to make sure the data exists in the db. How do I change the query so that find() is able to find it?
Thanks
You can use like this
db.myCollection.find({ myKey : /.*\$tes.*/i });
You have to escape $ by :

Find hashed data with MongoDB

Is it possible with MongoDB to find data by its hash?
I'm trying to find the MongoDB equivalent of this MySQL query:
SELECT column FROM table WHERE SHA1(column) = "value"
It doesn't seems there is any such functionality (a bit old, but couldn't find in docs.mongodb.com either), but you can include a library that contains sha1 functionality (e.g. js-sha1) in mongo shell with load function, then use it within your mongo operation.

MongoDB : Query with $where and space

I need to use $where in a mongoDB query like following :
$where:"this.extracted_service.DATA.MYKEY WITHSPACE.length >1"})
The problem is one of the key has a space in it so It won't work like that.
Any idea how to do it ?
Replace that with
$where:"this.extracted_service.DATA['MYKEY WITHSPACE'].length >1"