MongoDB not returning the Data - database

I created a database using MongoDB named mydb.
Then I created a collection called coll3
use mydb
db.coll3.insert({"1":"HI"})
When I do this
db.coll3.find()
I get this error
Couldn't retrieve documents
java.lang.IllegalStateException cannot be cast to t3.utils.document.g

You need to pass the query object (an empty object to return all documents) to the find function:
db.coll3.find({})
Refer to the MongoDB documentation.

Try:
db.getCollection('coll3').find({})

Related

How to access the value of a key-value pair within an array variable in Jmeter?

I have extracted this variable (userID_ALL) that contains the key-value pairs of some users. I would like to make a foreach loop that will call an API that will use the ID of each user. Is there a way to access the ID of the user in the foreach loop from the varible?
extracted key-value pairs from Json Extractor
I believe there should be a better way to get the IDs from the response, however if you have to deal with the variables as per your screenshot - you could fetch the "id" attribute value using the following __groovy() function:
${__groovy(new groovy.json.JsonSlurper().parseText(vars.get('userID')).id,)}
Demo:
More information:
JsonSlurper Documentation
Apache Groovy - Parsing and producing JSON
Apache Groovy - Why and How You Should Use It

How can I check if a field exists for a specific _id in mongodb collections?

I want to check if a specific _id in a collection has a field named 'report'. How do I do this in MongoDB?
Suppose my _Id is Je4F8X. All I want to do is to know if my asynchronous task has updated the DB with the output in the field 'report'.
Thanks in advance :)
To check if the field report is added to the document(earlier it was not present) by the 'tool' then you can simply use $exists query,
db.getCollection('yourCollection').find({_id:yourId, report:{$exists:true}})
If field was already present and want to check if it is updated with latest value use $eq.
This can work if storing output from tool in updatedValue is possible.
db.getCollection('yourCollection').find({_id:yourId, report:{$eq:updatedValue}})

Django - get queryset with id's not in set of values

According to doc -
https://docs.djangoproject.com/en/dev/topics/db/queries/#the-pk-lookup-shortcut -
I can get set of objects with specified in list ids. Is there any short way to get another set of objects, with id's not in the specified list. Blog.objects.filter(pk__not_in=[1,4,7]) - did not work for me. PS: is there any annotation of possible expresissions for filtering querysets, of making own short expressions?
Use the exclude method.
Blog.objects.exclude(pk__in=[1,4,7])
At first your query is wrong. You should write your query Blog.objects.filter(pk__in=[1,4,7]). And if you want to use not then you should read here

SQLALchemy - cannot reflect a SQL Server DB running on Amazon RDS

My code is simple:
app = Flask(__name__)
app.config.from_object('config')
db = SQLAlchemy(app)
db.metadata.reflect()
And it throws no errors. However, when I inspect the metadata after this reflection, it returns an empty immutabledict object.
The parameters in my connection string is 100% correct and the code works with non-RDS databases.
It seems to happen to others as well but I can't find a solution.
Also, I have tried to limit the reflection to specific tables using the "only" parameter in the metadata.reflect function, and this is the error I get:
sqlalchemy.exc.InvalidRequestError: Could not reflect: requested table(s) not available in mssql+pyodbc://{connection_string}: (users)
I've fixed it. The reflect() method of the SQLAlchemy class has a parameter named 'schema'. Setting this parameter, to "dbo" in my case, solved it.
I am using Flask-SQLAlchemy, which does not have the said parameter in its reflect() method. You can follow this post to gain access to that parameter and others, such as 'only'.
This error occurs when reflect is called without the schema name provided. For example, this will cause the error to happen:
metadata.reflect(only = [tableName])
It needs to be updated to use the schema of the table you are trying to reflect over like this:
metadata.reflect(schema=schemaName, only = [tableName])
You have to set schema='dbo' in parameter for reflect.
db.Model.metadata.reflect(bind=engine, schema='dbo', only=['User'])
and then create model of your table:
class User(db.Model):
__table__ = Base.metadata.tables['dbo.User']
and to access data from that table:

Working with columns having dot(.) in their name using GQL

I use Objectify for datastore operations in my GAE/Java application. I have used Objectify's #Embeded facility in a couple of places in my project. Objectify automatically flattens the nested objects within the entity marked by #Embeded notation using the . separator. Thus I have ended up with column names like entity.embededObject.Field
For example I have an entity 'Person' in my data store with two columns name and address.email.
I want to filter through Person in the datastore viewer by writing a simple GQL query.
But the following query fails with a syntax error:
SELECT * FROM Person where address.email='mail#gmail.com'
whereas the following works as it should
SELECT * FROM Person where name='Joe'
What am I doing wrong?
GQL currently doesn't support this - only 'word' characters are supported. You should definitely file this as a bug in the issue tracker.
Tested today, it is possible to run the following with backquotes
SELECT * FROM `your.kind`
I believe this holds true for any parameter, but please correct me if I am wrong.

Resources