Search code examples
mongodbt-sqlmongodb-queryopenquery

How to do OpenQuery in mongoDB


I want to do link mongodb servers within one query like SQL Linked server's OpenQuery concept. Is it possible in mongoDB?

SELECT 
    UserID,
    UserName,
    FirstName,
    LastName
FROM OPENQUERY(remotelinkedservername, 'SELECT * FROM dbo.Users' )

Solution

  • You can't do Open query logic in mongoDB but you can connect mongoDB with SQL server by using MongoDB new ODBC Driver with SQL Connector 2.1.0

    A linked server enables you to execute distribute queries against tables stored in a Microsoft SQL Server instance and another data store. Use the Microsoft SQL Server Management Studio to link your MongoDB data store to a SQL Server instance and then execute distribute queries against both data stores.