i want to query my data by time stamp
let date = new Date();
var today = new Date();
var yesterday = date.setDate(today.getDate() - 1);
console.log(date)
const dataTable = collection(db, 'sales')
let mquery = query(dataTable, where('createdDate', "<", yesterday))
const qSnap = await getDocs(mquery)
console.log(qSnap)
error : Uncaught (in promise) FirebaseError: Expected type 'mc', but it was: a custom xh object
The error that you encountered was produced by not using the query() method as pointed out by #AyseAsude. Now, after fixing the query, you should also convert the variable yesterday into a date format and iterate the items from the query. See code below:
let date = new Date();
var today = new Date();
var yesterday = new Date(date.setDate(today.getDate() - 1));
const dataTable = collection(db, 'sales')
let mquery = query(dataTable, where('createdDate', "<", yesterday))
const qSnap = await getDocs(mquery)
qSnap.forEach((doc) => {
// doc.data() is never undefined for query doc snapshots
console.log(doc.id, " => ", doc.data());
});
For more information, you check out this documentation.
You should use the query function and create Query instance.
import {query} from "firebase/firestore";
let mquery = query(dataTable, where('createdDate', "<", yesterday))
const qSnap = await getDocs(mquery)
Documentations to refer to:
https://firebase.google.com/docs/firestore/query-data/queries#simple_queries
https://firebase.google.com/docs/reference/js/firestore_#query
Related
I am currently getting a date format not recognized error when trying to fetch from a refcursor. The query used in pgAdmin for both the function call and fetch match exactly with the call coming from the .NET code and yet only the .NET code is throwing this error. The result set only consists of character_varying and numeric. Currently using .NET 6 with Npgsql 6.0.3.
await using var connection = new NpgsqlConnection(connectionString);
await connection.OpenAsync();
var tran = await connection.BeginTransactionAsync();
await using (var command = new NpgsqlCommand(query, connection)
{
CommandType = System.Data.CommandType.Text,
Transaction = tran
})
{
command.Parameters.Add(new NpgsqlParameter("refCursor", NpgsqlTypes.NpgsqlDbType.Refcursor, 10, "refCursor",
System.Data.ParameterDirection.ReturnValue, false, 2, 2, System.Data.DataRowVersion.Current, null));
command.Prepare();
var cursorName = "";
await using (var portal = await command.ExecuteReaderAsync())
{
while (portal.Read())
{
cursorName = portal[0].ToString();
}
}
command.CommandText = $"fetch all in \"{cursorName}\"";
command.CommandType = System.Data.CommandType.Text;
await using (var reader = await command.ExecuteReaderAsync())
The exception points to: File: char_todatetime.c Routine: execute_char_todatetime_format. Any ideas why?
I am using the following code to retrieve query parameters from URL but URLSearchParams returns an empty object.
PS: uselocation.search returning correct output.
const stringdata = useLocation().search
const queryparameter = new URLSearchParams(stringdata)
console.log("query parameter :", queryparameter)
const query = queryparameter.get('q');
var url_string = `http://localhost:3000/recipes${query}`
You can try using window.location.search over user search params.
That should look something like:
const queryParams = new URLSearchParams(window.location.search);
const query = queryParams.get('q');
let url_string = `http://localhost:3000/recipes${query}`;
The search property returns the querystring part of a URL, including the question mark (?).
const queryParams = new URLSearchParams(window.location.search);
Then you need to check if queryparameter.get('q') exists, otherwise it will return null and will append null to url.
let query;
if(queryParameter.has('q')){
query = queryparameter.get('q');
}
then
var url_string = `http://localhost:3000/recipes/${query}`
i have this reaction role system everything works up to the last part where the coulour slection happens
async run(message, client, con) {
await message.channel.send("Give the color for the embed.")
answer = await message.channel.awaitMessages(answer => answer.author.id === message.author.id,{max: 1});
var color = (answer.map(answers => answers.content).join()).toUpperCase()
if(color.toUpperCase()==='CANCEL') return (message.channel.send("The Process Has Been Cancelled!"))
function embstr(){
var finalString = '';
for(var i =0;i<n;i++){
finalString += b[i]+ ' - '+a[i] +'\n';
}
return finalString;
}
const botmsg = message.client.channels.cache.get(channel => channel.id === reactChannel)
const embed = new MessageEmbed()
.setTitle(embtitle)
.setColor(color)
.setDescription(embstr());
botmsg.send(embed);
message.channel.send("Reaction Role has been created successfully")
here is the error message
{
"stack": "TypeError: Cannot read property 'send' of undefined
at SlowmodeCommand.run (B:\\stuff\\Downloads\\Admeeeeeen bot\\src\\commands\\reactionroles\\createreactionrole.js:100:22)
at processTicksAndRejections (node:internal/process/task_queues:93:5)"
}
The .get() method takes in a snowflake as its parameter. AKA an ID of a certain object. It is not an iterator, meaning that what you're currently attempting to do is not right JavaScript wise.
Instead of passing in a parameter to represent a channel object, we'll just want to pass in the ID of the channel that we'd like to get. Alternatively, you could replace .get() with .find() there, which is in fact an iterator that uses this form of a callback, although it's insufficient in our case considering we can just use .get() which is more accurate when it comes to IDs.
/**
* Insufficient code:
* const botmsg = message.client.channels.cache.find(channel => channel.id === reactChannel)
*/
const botmsg = message.client.channels.cache.get(reactChannel /* assuming that reactChannel represents a channel ID */)
I am using React DatePicker to get the date and time for a booking.
Everything seems to work, i get the right date and it gets sent to the database but if i select let's say 10:30 as time, what i get to the database is 9:30, because apparently UTC is being used but i am in UTC + 1.
I tried the following to convert to UTC + 1 but both methods didn't work. What else can i try?
First method:
const date1 = new Date()
const inc = 1000 * 60 * 60 // an hour
const _date = new Date(date1)
const [startDate, setStartDate] = useState(
new Date( _date.getTime() + inc )
);
Second method:
function addHoursToDate(date, hours) {
return new Date(new Date(date).setHours(date.getHours() + hours));
}
const myDate = new Date();
const [startDate, setStartDate] = useState(
addHoursToDate(myDate, 1 )
);
Try to save the date in your database as milliseconds since the Unix Epoch. In this way, you can show the right date in your client without worry about the timezone.
const yourDate = new Date();
const millisSinceUnixEpoch = yourDate.getTime();
...save on db...
...get from db...
const yourDate = new Date(millisSinceUnixEpochFromDb);
i got this erroe even the command is working fine
(node:1907) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'fetchMembers' of undefined
client.on('message', async message => {
let guild = await message.guild.cache.fetchMembers();
let roleID= '644235497169748037';
let roleID1= '615852982734684181';
let roleID2= '615852983330013212';
let roleID3= '615852992230588427';
let roleID4= '722513324151144552';
let memberCount = guild.roles.get(roleID).members.size;
let memberCount1 = guild.roles.get(roleID1).members.size;
let memberCount2 = guild.roles.get(roleID2).members.size;
let memberCount3 = guild.roles.get(roleID3).members.size;
let memberCount4 = guild.roles.get(roleID4).members.size;
let memberCountChannel = guild.channels.get("733035179756486737")
let memberCountChannel1 = guild.channels.get("732530240420839464")
let memberCountChannel2 = guild.channels.get("732530312713863178")
let memberCountChannel3 = guild.channels.get("732530713898909746")
let memberCountChannel4 = guild.channels.get("732530791686602833")
memberCountChannel.setName("Guild Members: " + memberCount)
memberCountChannel1.setName("Wizard: " + memberCount1)
memberCountChannel2.setName("Witch: " + memberCount2)
memberCountChannel3.setName("Shai: " + memberCount3)
memberCountChannel4.setName("Compass: " + memberCount4)
});
Discord JS v12 introduces the concept of managers, you will no longer be able to directly use collection methods such as Collection#get on data structures like Client#users. You will now have to directly ask for a cache on a manager before trying to use collection methods.
You need to change:
guild.roles.get(roleID)
// to
guild.roles.cache.get(roleID)
and:
guild.channels.get(channelID)
// to
guilds.channels.cache.get(channelID)
Another error I saw in your code is that you are trying to access the property cache of Guild, which is nonexistent (message.guild.cache.fetchMembers()).
You'll have to use:
message.guild.members.fetch()