I wanted to ask if I want to get the first row in a table in mongoid, is it possible to write Model.first? without entering any conditions? Thanks
Yes, Model.first works as expected in Mongoid.
Just a quick example from an application I had running:
Loading development environment (Rails 3.1.0)
1.9.2p290 :001 > Hotel.first
=> #<Hotel _id: 4e94e8ab7d1645d6be00003c, _type: nil, created_at: 2011-10-12 01:08:59 UTC, updated_at: 2011-12-01 00:40:59 UTC, deleted_at: nil, name: "A hotel", code: "0545">
Yes, User.first will definitely work.
For meore options in querying you can refer documentation here
Related
i try'd to use \n but its not working. any ideas?
{
name: "learn-teambuilding",
title: "What Do We Know about Software Development in
Startups?",
content: [
'• use of easy-to-implement tools to facilitate product development Nevertheless, the absence of structure might hinder important activities.\ntest'
]
},
It's ok and already works for me ! you can also use back tick (this symbol: ``) and put your string in it
I am trying to obtain order book (buy, sell, volume, price) info from GDAX.
I am familiar with the Bittrex api - specifically this call:
https://bittrex.com/api/v1.1/public/getmarketsummary?market=usdt-eth
which produces the following response:
{
success: true,
message: "",
result: [
{
MarketName: "USDT-ETH",
High: 770,
Low: 729.70000005,
Volume: 12847.90985907,
Last: 752,
BaseVolume: 9641897.74525487,
TimeStamp: "2017-12-27T13:49:29.463",
Bid: 751.99999999,
Ask: 752.9999,
OpenBuyOrders: 2072,
OpenSellOrders: 1933,
PrevDay: 738.99899999,
Created: "2017-04-20T17:26:37.647"
}
]
}
Does anyone know what the equivalent call would be in the gdax api ?
I am using Python and tried out Client.get_product_order_book('ETH-USD')
but its output is limited and the order book seems rather thin.
In [54]: client.get_product_order_book('ETH-USD')
Out[54]:
{'asks': [['756.97', '168.24847073', 8]],
'bids': [['756.96', '77.74495889', 14]],
'sequence': 1810832728}
Based on the docs the call above with level=1 corresponds to the inside
(i.e. best bid and ask prices)
But the output from the Bittrex api seems to be the best bid and ask prices as
well. So does anyone know the difference ?
Does anyone know what the equivalent call would be in the gdax api ?
If you want something similar, a better try would be:
>> client.get_product_24hr_stats('ETH-USD')
>> {
"open": "416.11000000",
"high": "433.83000000",
"low": "410.11000000",
"volume": "91763.71115699",
"last": "432.79000000",
"volume_30day": "4011593.85194549"
}
I am using Python and tried out Client.get_product_order_book('ETH-USD') but its output is limited and the order book seems rather thin.
Level Description
1 Only the best bid and ask
2 Top 50 bids and asks (aggregated)
3 Full order book (non aggregated)
You are calling it with the default level of 1 so you are only getting the lowest ask and the highest bid, only 2, so yes, it's thin. If you need more info, consider calling it with level 2 or 3 according to the snippet above taken from the GDAX official docs. More here.
But the output from the Bittrex api seems to be the best bid and ask prices as well. So does anyone know the difference ?
The difference is that Bittrex only gives you the best bid and ask price while GDAX api gives you the bid/ask price, the total size of all the orders, and the number of orders.
I'm trying to figure out the best way to implement this.
If I have one large collection in my mongodb that holds all of my "Inventory" information for my warehouse without regard to the specific "type" of inventory, what is the best way to aggregate the data into their own collections continuously? **Added this information after-the-fact: I'm using a Mean stack so maybe some of this is better to just do server-side with an angular function rather than actually keeping a collection updated?
For instance, my current "Inventory" collection would have items such as
_id: something, name: item1, type: chemical, vendor: something, safetycode: ####, machineUse: n/a, equipmentUse: n/a ...
_id: something2, name: item2, type: machine, vendor: something2 safetycode: n/a, machineUse: "digging", equipmentUse: n/a ...
_id: something3, name: item3, type: equipment, vendor: something3 safetycode: n/a, machineUse: n/a, equipmentUse: "Computer" ...
I'm inclined to $group but is this best practice to keep a 'SEPERATE' collection updated with their respective groups? You'll notice in the following that the aggregate function should collect the specific 'type'(Chemical, Machine, equipment, etc...) and store all the details of each item collected with fields that are only used for that 'type' (i.e, Chemicals use 'safetycode', machines DO NOT use saftey code so it's left out and instead 'machineUse' is stored, etc.)
db.invfulls.aggregate([
{ "$group": {
"_id": "$itype",
"total": {$sum : 1},
"items":{
"$push":{
"$cond":{
"if": {"$eq":["$itype","Chemical"]},
"then": {"id":"$_id", "name":"$name", "vendor":"$vendor", "review":"$needsreview"},
"else": {"id":"$_id", "name":"$name", "vendor":"$vendor"}
}
}
}
}},
{$out: "invByType"}
])
Additionally, would I have to make this a function in the database and call that function anytime there is a new "post" made?
I've read a bit about the mapReduce as well but everything I read says it's a very slow and shouldn't be used?
I'm working on a project which needs to select data from Firebase on multiple fields.
I have a firebase database like this:
[{
date: "2016-01-29"
done: false
task: "hello world"
},
{
date: "2016-01-29"
done: false
task: "hello world"
}]
Now I want to query all data with date is today and done is true.
I look around google for a while but there's nothing work. Is there any one can please help me to figure this out?
You can only query on a single property with Firebase queries. So either you'll have to do the rest of the filtering client-side or you'll have to combine the values into a single 'date_done' property.
[{
date: "2016-01-29",
done: false,
date_done: "2016-01-29_false",
task: "hello world1"
},
{
date: "2016-01-29",
done: false,
date_done: "2016-01-29_false",
task: "hello world"
}]
Now you can get all the queries that were done on January 29 with:
ref.orderByChild('date_done').equalTo('2016-01-29_true').on(...
For some more information from people who asked similar questions, see:
NoSQL database design for queries with multiple restrictions (Firebase)
Query based on multiple where clauses in firebase
Firebase - How do I write multiple orderByChild for extracting data?
How to do the following query in Firebase? (more than one where condition)
Filter products on multiple child properties in Firebase
Let's say I'm building Twitter.
One of the tasks is to track, which tweets are read by particular user and store this data on server. When user requests somebody's feed, server should return:
[
{
id: 1,
tweet: "Hey there!",
isRead: false
},
{
id: 2,
tweet: "Here's my cat, look",
isRead: true
},
{
id: 2,
tweet: "Blue or yellow? Thats the question",
isRead: true
},
...
]
Which is the most efficient way to store data for which tweets are read by which user, and retrieving this data when returning somebody's feed for particular user?
Any ideas about data storing architecture are highly appreciated. My current stack is PostgreSQL for storing users and "tweets". Redis, MongoDB and neo4j are also used in the project, so available.
The first guess was to use Redis, like:
user_id: tweet_id
-----------------
user_id: tweet_id
-----------------
....
But I think, there may be better variants, more suitable for persistent data storage.
Thank you in advance.
Have a look at this Twitter-clone that Redis' author, antirez (a.k.a Salvatore Sanfilippo), had made: http://redis.io/topics/twitter-clone