this is my first question on this wonderful site, as usually I always found someone who asked before me :)
I have inherited a code and try to make it evolve and you will see in the way I ask that I am not familiar at all with this code... This is for my website, developed in REACT and the database is MongoDB. Here is the get function getting all the data from the MongoDB, filtered on relevant announces (it is not the exact .then, I simplified it to shorten the post):
import axios from "axios";
const axiosInstance = axios.create({
baseURL: config.api_url, headers: {"Content-Type": "application/json"}
});
export const getAnnounces = () => {
return new Promise((resolve, reject) => {
axiosInstance
.get("/announces?archived=false&status=publique")
.then(response => resolve({type: ADVERT_FOUND, announces: response.data})
My issue is that I would like to define a function getting all information except the images (which are in the collection and in some case increase the size of the export without added value). I tried this, but unsuccessfully
export const getAnnounces = () => {
return new Promise((resolve, reject) => {
axiosInstance
.get("/announces?archived=false&status=publique", { project: {images:0} })
.then(response => resolve({type: ADVERT_FOUND, announces: response.data})
Does someone know if it is possible to use .project or .projection with axios... if not, any idea/suggestion how to manage this?
Edit: thanks to feedback below, I went to the API, found the definition of getAnnounces in a way I better understand:
const getAnnounces = (req, res, next) => {const { filter, skip, limit, sort, projection } = aqp(req.query);
Announces.find(filter)
I changed simply to this, and it works perfectly!
Announces.find(filter,{images:0})
Thanks, Antoine