I'm not proficient in MongoDB and I have short question. What is the best structure for Questions - Answers Collections. Should I separate them to different collections or keep Answers as a property of Question? To give you more details:
Each question can have many Answers
I don't need to search in Answers
I will search in Questions
Each Answer will have userId, votes and of course answer properties
After finding Question, I will be able to expand Answers list and vote for the Answer
Questions will be also votable
It will be something like stackoverflow but much simpler. Thanks in advance.
I would keep them in two separated collections. As you said you have to be able to query in the questions collection so make a questions collection, you only have to show up answers realted for a specific selected question but will have some specific fields as you mentioned like votes. If we think about stackoverflow for example, you see the questions : click on the question --> then you can query an answers collection for the answer related to that question, also for answers you can have comments which if you not expect insane much of them can kept in a list along with the answer.You can keep the answers of the questions in a collection with a reference and an index on the question id.
Something like his one:
questions:
{
"_id" : ObjectId("52205df3d6c893638bc2aa14"),
"q" : "What is hip?",
"v" : 1000
}
answers :
{
"_id" : ObjectId("52205e72d6c893638bc2aa15"),
"q_id" : ObjectId("52205df3d6c893638bc2aa14"),
"a" : "Tell me, tell me!",
"u" : "uid",
"v" : 153,
"c" : [
{
"c" : "Cool",
"u" : "uid",
"v" : 100
}
]
}
Related
I am looking for a rest way to get more information out of a COVID19 map.
I noticed that arcgis provides plenty of topics and tutorials for developers.
I just don't know which tutorials are helping me to understand the FeatureServer.
I had two questions, can I query the below table with the rest api?
Like finding out what fields are in it, and what data.
If I have access to a serviceItemId - can I do anything useful with it?
"tables" : [
{
"id" : 0,
"name" : "RKI_COVID19",
"parentLayerId" : -1,
"defaultVisibility" : true,
"subLayerIds" : null,
"minScale" : 0,
"maxScale" : 0
}
]
Now I know how the query works.
https://developers.arcgis.com/rest/services-reference/query-related-records-feature-service-.htm
I found answers to what I was looking for.
Try this to access all data (query=1=1) in formatted son (pjson):
https://services7.arcgis.com/mOBPykOjAyBO2ZKk/arcgis/rest/services/RKI_COVID19/FeatureServer/0/query?where=1%3D1&outFields=*&f=pjson
Or have a look at this notebook that implements the data retrieval from there:
https://github.com/starschema/COVID-19-data/blob/master/notebooks/RKI_GER_COVID19_DASHBOARD.ipynb
I'm currently researching on functionalities on Algolia for a location service. I have a simple question.
Is it possible to search with multiple "like" string, something similar to as below in MySQL?
select * from route
WHERE pickup LIKE "51%"
AND dropoff LIKE "80%";
On Algolia, let's assume there is a simple index consists of small data:
[{
"pickup" : "51105",
"dopoff" : "80637"
},
{
"pickup" : "51105",
"dopoff" : "39871"
},
{
"pickup" : "32791",
"dopoff" : "40545"
}]
I've checked it can be retrieved by given exactly two params, like:
index.search({
facetFilters: 'pickup: 51105, dropoff:80637',
}
Also we can use normal query with typo for one of target params,
index.search({
query: '51',
restrictSearchableAttributes: [
'pickup'
],
}
but neither of them is satisfied with my original requirement.
I've found a post that might be related to my question in algolia community, but It woundn't give me much insights.
Querying multiple terms in multiple fields
I'd think there is a solution as I believe this'd be a quite common use-case.
It would be great if anybody has encountered similar situation or some insights. Thanks a lot.
I think the best equivalent of MySQL LIKE queries applied to facets would be to use searchForFacetValues.
Here is the documentation about the feature: https://www.algolia.com/doc/api-client/javascript/search/#search-for-facet-values
First, I'd like to say that I really love NoSQL & MongoDB but I've got some major concerns with its schema-less aspect.
Let's say I have 2 tables. Employees and Movies.
And... I have a very stupid data layer / framework that sometimes like to save objects in the wrong tables.
So one day, a Movie gets saved in the Employees table. Like this:
> use mongoTests;
switched to db mongoTests
> db.employees.insert({ name : "Max Power", sex : "Male" });
> db.employees.find();
{ "_id" : ObjectId("4fb25ce6420141116081ae57"), "name" : "Max Power", "sex" : "Male" }
> db.employees.insert({ title : "Fight Club", actors : [{ name : "Brad Pitt" }, { name : "Edward Norton" }]});
> db.employees.find();
{ "_id" : ObjectId("4fb25ce6420141116081ae57"), "name" : "Max Power", "sex" : "Male" }
{ "_id" : ObjectId("4fb25db834a31eb59101235b"), "title" : "Fight Club", "actors" : [ { "name" : "Brad Pitt" }, { "name" : "Edward Norton" } ] }
This is VERY wrong.
Let's switch the context, think about Movies, and CreditCards (for whatever reason, in this context credit cards would be stored in clear text inside the DB). This is SUPER WRONG?
The code would probably explode because it's trying to use an object
structure and receives another totally unknown structure.
Even worst, the code actually works and the webstore visitors
actually see credit cards information in the "Rent a movie" list.
Is there anything, built-in that would prevent such threat to ever happen? Like some way to "force" a schema to be respected for only some tables?
Or is there any way to force MongoDB to make a schema mandatory? (Can't create new fields in a table, etc)
EDIT: For those who thinks I'm trolling, I'm really not, this is an important question for me and my team because this is a big decision whether or not we're going to use NoSQL.
Thanks and have a nice day.
The schema-less aspect is one of the major positives.
A DB with a schema doesn't fully remove this kind of issue - e.g. there could be a bug in a system that uses a RDBMS that puts the wrong data in the wrong field/table.
IMHO, the bigger concern would be, how did that kind of bug make it through dev, testing and out into production?!
Having said that, you could set up a process that checks the "schema" of documents within a collection (e.g. look at newly added documents, check whether they have fields you would expect to see in there) - then flag up for investigation. There is such a tool (node.js) here (I think, I've never used it):
http://dhendo.github.com/node-mongodb-schema-validator/
Edit:
For those finding this question in future, so the link in my comment doesn't go overlooked, there's a jira item for this kind of thing here:
http://jira.mongodb.org/browse/SERVER-3536
The official MongoDB api wrote very little about $ne
http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24ne
So when I encountered something like
db.papers.update({"authors cited" : {"$ne" : "Richie"}},
... {$push : {"authors cited" : "Richie"}})
I have no choice but to become utterly confused. Can someone please explain it to me?
This would add "Richie" to the list of authors cited for a paper that does not already have "Richie" as an author.
An alternative would be to use $addToSet.
But then how would I know whether {"authors cited" : {"$ne" : "Richie"}} means the elements in the list corresponding to "author cited", vs the value corresponding to "author cited"?
That is a bit confusing. Generally (I am sure there are exceptions, but those should be documented), all selectors target the individual values for multi-values fields. In Mongo this is called "multikeys" .
Note that this led me to assume initially that your query would target all papers that have at least one author who is not Richie. Then I checked and this turned out to be wrong. +1 for your question, because this really needs to be documented better.
I'm about to start a new Project and need some advise.
For example, if i have a Model named "Page" that has "Posts" - how can i store more than one language when i create a new post and show only posts in a language when i click a - let's say - flag-icon at the top.
I have read a lot about l18n but as i understood - this is the way if i want to translate static messages like errors etc. ?
Hope somebody could explain a given strategy to to this in a clean way.
Thanks!
Like you said, localization and internationalization (abbreviated l10n and i18n, respectively) typically refer to the localization of the software product itself, rather than the content.
There are different strategies on how to manage content in multiple languages, and it does depend a lot on what you want to achieve. Suppose you operate a multilingual blog. However, some content is not relevant to an international audience, so you don't want to supply an English version (assuming your not a native English speaker, but I guess the point is clear).
Now it seems to make sense to simply not display that blog post in the English version of the blog. Hence, I'd suggest
Post {
"_id" : ObjectId('...'),
"PostGroupId: ObjectId('...'),
"Title" : "A Blog Post Title",
"Text" : "<h1>Lorem ipsum</h1> lots of text",
"Language" : "en",
"Published" : // and so on...
}
You can now easily query for all or specific posts in a given language: db.Posts.find({"language" : "en"}).sort({"Published" : -1});
Depending on your needs, you might want to add a grouping object for the posts to associate translations of posts to each other explicitly, using denormalized data:
PostGroup
{
"_id" : ObjectId('...'),
// ...
"Posts" : [{"lang" : "en", "id" : ObjectId('...')},
{"lang" : "de", "id" : ObjectId('...')} ]
// -- or simpler --
"AvailableLanguages" : ["en", "it", "fr"]
}