Most Imporatant Mongodb Interview questions Read here>!


If you're looking for MongoDB Interview Questions and Answers for Experienced & Freshers, you are at right place. There are lot of opportunities from many reputed companies in the world. According to research MongoDB has a market share of about 4.5%. So, You still have opportunities to move ahead in your career in MongoDB. Mindmajix offers advanced MongoDB Interview Questions and Answers that helps you in cracking your interview & acquire your dream career.
Q. What’s a good way to get a list of all unique tags?
What’s the best way to keep track of unique tags for a collection of documents millions of items large? The normal way of doing tagging seems to be indexing multikeys. I will frequently need to get all the unique keys, though. I don’t have access to mongodb’s new “distinct” command, either, since my driver, erlmongo, doesn’t seem to implement it, yet.
Even if your driver doesn’t implement distinct, you can implement it yourself. In JavaScript (sorry, I don’t know Erlang, but it should translate pretty directly) can say:
result = db.$cmd.findOne({“distinct” : “collection_name”, “key” : “tags”})
So, that is: you do a findOne on the “$cmd” collection of whatever database you’re using. Pass it the collection name and the key you want to run distinct on.
If you ever need a command your driver doesn’t provide a helper for, you can look at HTTP://WWW.MONGODB.ORG/DISPLAY/DOCS/LIST+OF+DATABASE+COMMANDS  for a somewhat complete list of database commands.
Q. MongoDB query with an ‘or’ condition
I have an embedded document that tracks group memberships. Each embedded document has an ID pointing to the group in another collection, a start date, and an optional expire date.
I want to query for current members of a group. “Current” means the start time is less than the current time, and the expire time is greater than the current time OR null.
This conditional query is totally blocking me up. I could do it by running two queries and merging the results, but that seems ugly and requires loading in all results at once. Or I could default the expire time to some arbitrary date in the far future, but that seems even uglier and potentially brittle. In SQL I’d just express it with “(expires >= Now()) OR (expires IS NULL)” – but I don’t know how to do that in MongoDB.
Just thought I’d update in-case anyone stumbles across this page in the future. As of 1.5.3, mongodb now supports a real $ or operator:
https://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24 or
Your query of “(expires >= Now()) OR (expires IS NULL)” can now be rendered as:
{$or: [{expires: {$gte: new Date()}}, {expires: null}]}
In case anyone finds it useful, www.querymongo.com does translation between SQL and MongoDB, including OR clauses. It can be really helpful for figuring out syntax when you know the SQL equivalent.
In the case of OR statements, it looks like this
SQL:
SELECT * FROM collection WHERE columnA = 3 OR columnB = ‘string’;
MongoDB:
db.collection.find({
“$or”: [{
“columnA”: 3
}, {
“columnB”: “string”
}]
});

Comments

  1. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. What is the primary goal of Ethical hacking, and how does it differ from malicious hacking?

      The primary goal of Ethical hacking, also known as penetration testing or white-hat hacking, is to identify and address vulnerabilities in computer systems, networks, or applications. Ethical hackers, authorized by the organization, use their skills to simulate potential cyber attacks to uncover security weaknesses. This proactive approach helps organizations strengthen their security posture and protect against real malicious hackers.

      Delete
  2. What key responsibilities does a Cloud Architect undertake in designing and implementing cloud-based solutions?

    A Cloud Architect plays a pivotal role in designing and implementing cloud solutions. Key responsibilities include defining cloud architectures, selecting appropriate cloud services, ensuring security and compliance, optimizing performance, and overseeing the integration of various cloud technologies. They also collaborate with stakeholders to understand business requirements, assess scalability needs, and design resilient and cost-effective cloud infrastructures.

    ReplyDelete
  3. What is the purpose of exploratory data analysis (EDA) in the field of data analytics?
    Answer: Exploratory Data analysis (EDA) is a crucial step in data analytics that aims to understand the underlying patterns, relationships, and trends within a dataset. It involves techniques such as summary statistics, data visualization, and hypothesis testing to uncover insights and inform subsequent modeling or decision-making processes.

    ReplyDelete

Post a Comment

Popular posts from this blog

SAP FI (Financial Accounting) Module

Oxyloans Online Peer-to-Peer Lending & Borrowing, Personal Loans, Technology Loans, SME Loans in hyderabad

Professional Makeup artist in hyderabad & Hairstyling academy - First Foundation PRO