Home > database >  MongoDb4.2 how to realize the Inner join or where the exists (sub-queries) effect
MongoDb4.2 how to realize the Inner join or where the exists (sub-queries) effect

Time:09-17

The SQL version:
 
The select Anderson d, a.n ame, a.x xx
From A A
Where the exists (select 1 from B to B where b. lag=0 and p. id=Anderson d)
And a.n ame like '% xx %'



Two sets, respectively are millions, even thousands of data; Directing how to implement the above requirements, please?

See online say mongo are flat design, not suitable for this association query; This demand, that is how to implement?

For example, is A user table, table B is order
Want to query in [1 October solstice on October 3, buy a mobile hard disk users] (orders), and dependency [users] in Beijing (user table), finally the results returned, as long as the users table field


Oracle partitioned index, but the query efficiency is very low,

CodePudding user response:

Directing a relational query is not

CodePudding user response:

Use nested document way, don't know how to efficiency,

 
Db. Test1. Aggregate ([
{$match: {" users. The account ":" user5 "}},
{$project: {id: 1, name: 1}}
])

CodePudding user response:

Relational data suggest or stored in the relational database
In a relational database, the query performance difference lies mainly in your LIKE, if it's not LIKE the query, this demand is soon

CodePudding user response:

 db. Anderson nsertMany ([{id: 1, name: 'xx1}, {id: 2, name: "xx2"}, {id: 3, name:' aa1}, {id: 4, name: 'aa2}]) 
Db. B.i nsertMany ([{id: 1, pid: 1, the flag: 0}, {id: 2, pid: 2, flag: 1}, {id: 3, pid: 3, flag: 0}, {id: 4, pid: 4, flag: 1}])
Db. A.a ggregate ([
{$match: {name:/xx/}},
{$lookup: {
From: 'b', as: 'b_doc'
Let: {id: '$id'},
Pipeline: [
{$match: {$expr flag: 0: {$eq: [' $pid ', '$$id']}}}
]
}},
{$match: {' b_doc. _id ': {$exists: true}}},
{$project: {b_doc _id: 0:0}}
])

CodePudding user response:

New area index, index of id can contain the characteristics of the character difference area
When retrieving
1 scan index for the actual data of id,
2 use the id to get data
  • Related